-
I pared down this example JSON as much as I could while still retaining it's structure. Can someone give me some pointers on how to iterate this? I'm not sure how to handle having unknown array sizes at multiple levels (the geometry coords can be hundreds). {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties":
{
"NAME": "Arkansas",
"CENSUSAREA": 52035.477000
},
"geometry":
{
"type": "Polygon",
"coordinates": [
[
[-94.042964, 33.019219],
[-94.042964, 33.019219]
]
]
}
},
{
"type": "Feature",
"properties":
{
"NAME": "California",
"CENSUSAREA": 155779.220000
},
"geometry":
{
"type": "MultiPolygon",
"coordinates": [
[
[
[-120.248484, 33.999329],
[-120.248484, 33.999329]
]
],
[
[
[-119.789798, 34.057260],
[-119.789798, 34.057260]
]
]
]
}
}
]
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Objects and arrays can both be access with Assuming you parsed the above JSON to a variable To iterate, just use |
Beta Was this translation helpful? Give feedback.
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" withj["features"][0]["properties"]["NAME"]
.To iterate, just use
begin()
/end()
just like astd::vector
orstd::map
. For easier access to keys and values in objects, there is theitems
method.