I'm using JSONObject class from a lib already included, and I don't mind changing to another one if I need it.
I know how to iterate over JSONArrays, but when I parse JSON data coming from Facebook, I get only JSONObject, not an array, and I would like to access that particular item at a certain index-JSONObject[0] for the first one. Which is impossible for me.
"http://http://url.com/": {
"id": "http://http://url.com//"
}, "http://url2.co/": {
"id": "http://url2.com//",
"shares": 16
}
,
"http://url3.com/": {
"id": "http://url3.com//",
"shares": 16
}
End
JSONObject keys () method will return a JSONArray of the JSONObject keys, so we can just walk though it in loop in order to iterate over the elements:
JSONObject object = new JSONObject ();
JSONArray keys = object.names ();
for (int i = 0; i keys.length (); i++) {
String key = keys.getString (i);
String value = object.getString (key);
}