Android JSON parsing of multiple JSONObjects inside JSONObject

Check this answer , that way you don't need to know the keys, and can just loop through and access the inner object, but categories would be better as a JSONArray rather than an Object, that way you could just normally loop through

for(int i = 0; i < array.length(); i++) {
    JSONObject obj = myArray.get(i);
    ....
}

here you can retrieve all your json data, ask for a specific key and innerKey to get what you want, cheers

    try
    {   
        String jsonString="";//your json string here
        JSONObject jObject= new JSONObject(jsonString).getJSONObject("categories");
        Iterator<String> keys = jObject.keys();
        while( keys.hasNext() )
        {
            String key = keys.next();
            Log.v("**********", "**********");
            Log.v("category key", key);
            JSONObject innerJObject = jObject.getJSONObject(key);
            Iterator<String> innerKeys = innerJObject.keys();
            while( innerKeys.hasNext() )
            {
                String innerKkey = keys.next();
                String value = innerJObject.getString(innerKkey);
                Log.v("key = "+key, "value = "+value);
            }
        }
    }
    catch (JSONException e)
    {   e.printStackTrace();    }

Tags:

Java

Json

Android