0

I have a json object being returned that has multiple arrays within the json object. I am able to parse a json object if it has one array in it (with jObject.getJSONArray("2013-10-30")), but not multiple. The amount of arrays (i.e. the dates) would be changing almost everyday (some days there wouldn't be any) and that is where I get stuck. I'm not sure how to get a list of all the array names and then iterator through that.

{
"2013-10-30": [
    {
        "id": "399",
        "Time": "00:50:46"
    }
],
"2013-10-29": [
    {
        "id": "398",
        "Time": "21:44:09"
    },
    {
        "id": "393",
        "Time": "10:53:01"
    }
]
}
1
  • UsejObject.keys() to obtain an Iterator of the string names (in your case the dates). See the keys() method of the JSONObject class. Commented Nov 1, 2013 at 2:07

1 Answer 1

2

You should iterate over the keys and get the JSONArray for each key as follow:

Iterator<String> keys = jObject.keys();
while(keys.hasNext()){
    String key = keys.next();
    try{
         JSONArray array = jObject.getJSONArray(key);
         // do something with the array
         // ...
    }
    catch(Exception e){
        e.printStackTrace()
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.