-2

[Android] I have a JSON File that it is composed in this way:

 "5":{
        "15":{
            ...
        },
        "18":{
           ..
        },
        "7":{
            ...
        },
        "9":{
            ..
        }
    }
}

How I can extract the infomation at 15,18,7,9? this number 15, 18 ,7, 9 change from run to another.. My Code is:

JSONObject obj = new JSONObject(file);
            JSONArray uno = obj.getJSONArray("5");

and I obtain JSONException!! Anyone can help me?

Marc
  • 3,683
  • 8
  • 34
  • 48
Gozilla
  • 13
  • 3
  • asked bazillion times ... "Alex", "Kodie","Lache" are keys (in json terminology)... now, get back to googling – Selvin Mar 31 '15 at 16:22
  • of course you do. look at the structure of your json file. now look at the method you call. now look at the doc for the method you call if that's not clear enought already. – njzk2 Mar 31 '15 at 16:45
  • possible duplicate of [How to parse data from json in android?](http://stackoverflow.com/questions/13620414/how-to-parse-data-from-json-in-android) – Maveňツ Mar 31 '15 at 20:36

1 Answers1

0

http://developer.android.com/reference/org/json/JSONObject.html

5 is not a JSONarray, it is a key. Try obj["5"] from the above documentation, then calling keys to get the keys to access the internal attributes.

Hypaethral
  • 1,467
  • 16
  • 22