Skip to content

How do I iterate this variable structure? #2295

Answered by nlohmann
Murphest asked this question in Q&A
Discussion options

You must be logged in to vote

Objects and arrays can both be access with operator[]. For an object, you pass the key; for an array, you pass the index.

Assuming you parsed the above JSON to a variable j, you can access the string "Arkansas" with j["features"][0]["properties"]["NAME"].

To iterate, just use begin()/end() just like a std::vector or std::map. For easier access to keys and values in objects, there is the items method.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Murphest
Comment options

@Murphest
Comment options

@nlohmann
Comment options

@Murphest
Comment options

@nlohmann
Comment options

Answer selected by nlohmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants