Skip to content
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

how two get key name using json object? #24

Closed
qtbhappy opened this issue Apr 11, 2016 · 2 comments
Closed

how two get key name using json object? #24

qtbhappy opened this issue Apr 11, 2016 · 2 comments

Comments

@qtbhappy
Copy link

hi, suppose we have a json string like jsonstr="{"customer":[{"name":"mary", "level":5},{"name":"peter", "level":6}]}"
after converted to json object in vba, I wonder how to get key names, such as name, level?

@timhall
Copy link
Member

timhall commented Apr 11, 2016

You can get the keys/items for objects with the following:

Dim Parsed As Dictionary
Set Parsed = JsonConverter.ParseJson(jsonstr)

Parsed.Keys ' => Array("customer")
Parsed("customer")(1).Keys ' => Array("name", "level")
Parsed("customer")(1).Items ' => Array("mary", 5)
Parsed("customer")(2).Keys ' => Array("name", "level")
Parsed("customer")(2).Items ' => Array("peter", 6)

Dim Key As Variant
'          ^ Need Variant/Object for For Each

For Each Key in Parsed("customer")(1).Keys
    Debug.Print Key
Next Key
' -> name
'    level

@timhall timhall closed this as completed Apr 11, 2016
@qtbhappy
Copy link
Author

great,thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants