Q:

how to parse this nested json response?

I am getting  json response in this format.
{
   "apiGroups":
   {
       "Affiliate":
       {
           "listingsAvailable":
           {
               "Beauty_Personal_Care":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:586:821655440?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Eyewear":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:473:662748456716?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Real_Estate":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:897:673143570606?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Jewellery":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:6:315773046?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Furniture":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:580:1894930153?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Tweens_Boys":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:814:934253466?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Automobiles":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:1145:639299259208?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Home_Improvement":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:864:624389489778?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "The_Designer_Studio":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:924:655684426383?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },
               "Fashion_Jewellery":
               {
                   "listingVersions":
                   {
                       "v1":
                       {
                           "get": "http://affiliate-feeds.snapdeal.com/feed/api/category/v1:1113:672114192240?expiresAt=1446085800024&signature=civtucyhsbufsjzjvqfa"
                       }
                   }
               },

I need to get categories like beauty personal care, eye ware and their respective urls in get field.How can i loop through this and get the.So far i tried like this and dont no how to proceed next.Can anybody give me suggestions how to parse this json?
json = jParser.getJSONFromUrl(response);
JSONObject api = json.getJSONObject("apiGroups");
JSONObject affiliate = api.getJSONObject("Affiliate");
JSONObject list = affiliate.getJSONObject("listingsAvailable");

A:

You can read the documentation about the JSONObject class in Android.
In this documentation, you will find the method keys that will "Returns an iterator of the String names in this object."
So you just have to call this method and use the iterator.
Iterator<String> keysIterator = jsonObject.keys();
String key;
while (keysIterator.hasNext()) {
     key = keysIterator.next();
     //use the key to retrieve the data form jsonObject
}

However, if you are the one generating this json, you may consider changing it a bit. The data in the listingsAvailable should probably be in an array.

