-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json data include collections, how to get value of collections. thanks. #280
Comments
Please share your code, what have you tried?
On Thursday, January 2, 2025 at 04:31:39 AM EST, poplarfeng ***@***.***> wrote:
I want get the first "id" value of schedule->2024->6th, how to use the vba-json?
json as belows.
{
"code": "0001",
"message": "success",
"schedule": {
"2024": {
"6th":[
{
"id": "1699",
"strong_base_id": "688",
"schedule": "2024-06",
},
{
"id": "1700",
"strong_base_id": "688",
"schedule": "2024-06",
}
]
}
}
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
There seems to be 2 issues with your JSON:
The colon there is actually a Fullwidth Colon instead of a regular colon.
If I fix those and format your json to be more readable, we get the following: {
"code": "0001",
"message": "success",
"schedule": {
"2024": {
"6th": [
{
"id": "1699",
"strong_base_id": "688",
"schedule": "2024-06"
},
{
"id": "1700",
"strong_base_id": "688",
"schedule": "2024-06"
}
]
}
}
}
With that, your VBA code could look like the following: Dim JsonString As String
JsonString = "{""code"": ""0001"",""message"": ""success"",""schedule"": {""2024"": {""6th"": [{""id"": ""1699"",""strong_base_id"": ""688"",""schedule"": ""2024-06""},{""id"": ""1700"",""strong_base_id"": ""688"",""schedule"": ""2024-06""}]}}}"
Dim Json As Dictionary
Set Json = ParseJson(JsonString)
Debug.Print Json("schedule")("2024")("6th")(1)("id")
Note that the use of Also, it might be a better practice to use the Debug.Print Json.Item("schedule").Item("2024").Item("6th").Item(1).Item("id") |
Thanks,DecimalTurn. Your reply answered my question. Thanks again. |
@poplarfeng my pleasure! Feel free to close the issue as resolved. |
resolved. |
I want get the first "id" value of schedule->2024->6th, how to use the vba-json?
json as belows.
{
"code": "0001",
"message": "success",
"schedule": {
"2024": {
"6th":[
{
"id": "1699",
"strong_base_id": "688",
"schedule": "2024-06",
},
{
"id": "1700",
"strong_base_id": "688",
"schedule": "2024-06",
}
]
}
}
}
The text was updated successfully, but these errors were encountered: