I have the following json returned to me from an API.
"sections": {
"1": {
"title":"Within 1 Km",
"count":6
},
"3": {
"title":"Within 3 Km",
"count":1
},
....and some more here
It's worth nothing this is not a JSON Array.
I need to iterate through the objects contained with sections, but because it is not a JSON array, I'm extracting the names ("1", "3", and so on) and looping through the JSON selecting each object.
JSONObject jsSecs = new JSONObject(data).getJSONObject("sections");
JSONArray jsSecsArray = jsSecs.names();
What I've noticed is that JSONArray.names() will return an array of names out of order from the JSON.
I expected 0th element to contain "1", 1st element to contain "3".
What I got was 0th element to contain "10", 2nd element to contain "1", etc - all out of sync.
What's going on here? Have I missed something obvious? I don't want to reorder things if I don't have to. It seems like more fuss than it's worth.