title: JSON parsing with dynamic JSON object name?
body: <p>I know the JSON parsing, but in my current project I am getting something different kind of JSON format, where name of all objects are dynamic, and they may be change.</p>
  
  <pre><code>{
      "category_id": "1",
      "parent_id": "0",
      "name": "Root Catalog",
      "is_active": null,
      "position": "0",
      "level": "0",
      "children": {
          "0": {
              "category_id": "2",
              "parent_id": "1",
              "name": "Default Category",
              "is_active": "1",
              "position": "1",
              "level": "1",
              "children": {
                  "0": {
                      "category_id": "32",
                      "parent_id": "2",
                      "name": "Services",
                      "is_active": "1",
                      "position": "1",
                      "level": "2",
                      "children": {
                          "0": {
                              "category_id": "20",
                              "parent_id": "32",
                              "name": "Makeup",
                              "is_active": "1",
                              "position": "1",
                              "level": "3",
                              "children": {
                                  "0": {
                                      "category_id": "22",
                                      "parent_id": "20",
                                      "name": "Bridal Makeup",
                                      "is_active": "1",
                                      "position": "1",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "1": {
                                      "category_id": "23",
                                      "parent_id": "20",
                                      "name": "General Makeup",
                                      "is_active": "1",
                                      "position": "2",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  }
                              }
                          },
                          "1": {
                              "category_id": "21",
                              "parent_id": "32",
                              "name": "Skin Services",
                              "is_active": "1",
                              "position": "2",
                              "level": "3",
                              "children": {
                                  "0": {
                                      "category_id": "24",
                                      "parent_id": "21",
                                      "name": "Bleach",
                                      "is_active": "1",
                                      "position": "1",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "1": {
                                      "category_id": "25",
                                      "parent_id": "21",
                                      "name": "Cleanup",
                                      "is_active": "1",
                                      "position": "2",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "2": {
                                      "category_id": "26",
                                      "parent_id": "21",
                                      "name": "General Facials",
                                      "is_active": "1",
                                      "position": "3",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "3": {
                                      "category_id": "27",
                                      "parent_id": "21",
                                      "name": "Masks",
                                      "is_active": "1",
                                      "position": "4",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "4": {
                                      "category_id": "28",
                                      "parent_id": "21",
                                      "name": "Special Facials",
                                      "is_active": "1",
                                      "position": "5",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "5": {
                                      "category_id": "29",
                                      "parent_id": "21",
                                      "name": "Threading",
                                      "is_active": "1",
                                      "position": "6",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "6": {
                                      "category_id": "30",
                                      "parent_id": "21",
                                      "name": "Waxing",
                                      "is_active": "1",
                                      "position": "7",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "7": {
                                      "category_id": "38",
                                      "parent_id": "21",
                                      "name": "Special Services",
                                      "is_active": "1",
                                      "position": "8",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "8": {
                                      "category_id": "40",
                                      "parent_id": "21",
                                      "name": "Lip Care",
                                      "is_active": "1",
                                      "position": "9",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "9": {
                                      "category_id": "41",
                                      "parent_id": "21",
                                      "name": "Eye Care",
                                      "is_active": "1",
                                      "position": "10",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  }
                              }
                          },
                          "2": {
                              "category_id": "3",
                              "parent_id": "32",
                              "name": "Body Services",
                              "is_active": "1",
                              "position": "3",
                              "level": "3",
                              "children": {
                                  "0": {
                                      "category_id": "4",
                                      "parent_id": "3",
                                      "name": "Body Wraps",
                                      "is_active": "1",
                                      "position": "1",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "1": {
                                      "category_id": "5",
                                      "parent_id": "3",
                                      "name": "Reflexology",
                                      "is_active": "1",
                                      "position": "2",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "2": {
                                      "category_id": "6",
                                      "parent_id": "3",
                                      "name": "Special Body Services",
                                      "is_active": "1",
                                      "position": "3",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  }
                              }
                          },
                          "3": {
                              "category_id": "7",
                              "parent_id": "32",
                              "name": "Hair Services",
                              "is_active": "1",
                              "position": "4",
                              "level": "3",
                              "children": {
                                  "0": {
                                      "category_id": "8",
                                      "parent_id": "7",
                                      "name": "Chemical Treatments",
                                      "is_active": "0",
                                      "position": "1",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "1": {
                                      "category_id": "42",
                                      "parent_id": "7",
                                      "name": "Hair Extensions",
                                      "is_active": "1",
                                      "position": "2",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "2": {
                                      "category_id": "9",
                                      "parent_id": "7",
                                      "name": "Hair Color",
                                      "is_active": "1",
                                      "position": "3",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "3": {
                                      "category_id": "10",
                                      "parent_id": "7",
                                      "name": "Haircut",
                                      "is_active": "1",
                                      "position": "4",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "4": {
                                      "category_id": "11",
                                      "parent_id": "7",
                                      "name": "Hair Straightening",
                                      "is_active": "1",
                                      "position": "5",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "5": {
                                      "category_id": "12",
                                      "parent_id": "7",
                                      "name": "Hair Styling",
                                      "is_active": "1",
                                      "position": "6",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "6": {
                                      "category_id": "13",
                                      "parent_id": "7",
                                      "name": "Hair Treatments",
                                      "is_active": "1",
                                      "position": "7",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "7": {
                                      "category_id": "14",
                                      "parent_id": "7",
                                      "name": "Other Hair Services",
                                      "is_active": "1",
                                      "position": "8",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "8": {
                                      "category_id": "15",
                                      "parent_id": "7",
                                      "name": "Special Hair Services",
                                      "is_active": "1",
                                      "position": "9",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  }
                              }
                          },
                          "4": {
                              "category_id": "16",
                              "parent_id": "32",
                              "name": "Hands And Feet",
                              "is_active": "1",
                              "position": "5",
                              "level": "3",
                              "children": {
                                  "0": {
                                      "category_id": "17",
                                      "parent_id": "16",
                                      "name": "Manicure",
                                      "is_active": "1",
                                      "position": "1",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "1": {
                                      "category_id": "18",
                                      "parent_id": "16",
                                      "name": "Nail Art",
                                      "is_active": "1",
                                      "position": "2",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  },
                                  "2": {
                                      "category_id": "19",
                                      "parent_id": "16",
                                      "name": "Pedicure",
                                      "is_active": "1",
                                      "position": "3",
                                      "level": "4",
                                      "children": {
  
                                      }
                                  }
                              }
                          }
                      }
                  },
                  "1": {
                      "category_id": "33",
                      "parent_id": "2",
                      "name": "Memberships",
                      "is_active": "1",
                      "position": "2",
                      "level": "2",
                      "children": {
  
                      }
                  },
                  "2": {
                      "category_id": "34",
                      "parent_id": "2",
                      "name": "Packages",
                      "is_active": "1",
                      "position": "3",
                      "level": "2",
                      "children": {
  
                      }
                  },
                  "3": {
                      "category_id": "35",
                      "parent_id": "2",
                      "name": "Offers",
                      "is_active": "1",
                      "position": "4",
                      "level": "2",
                      "children": {
  
                      }
                  },
                  "4": {
                      "category_id": "36",
                      "parent_id": "2",
                      "name": "Customer Reviews",
                      "is_active": "1",
                      "position": "5",
                      "level": "2",
                      "children": {
  
                      }
                  },
                  "5": {
                      "category_id": "37",
                      "parent_id": "2",
                      "name": "Gallery",
                      "is_active": "1",
                      "position": "6",
                      "level": "2",
                      "children": {
  
                      }
                  },
                  "6": {
                      "category_id": "31",
                      "parent_id": "2",
                      "name": "Contact us",
                      "is_active": "1",
                      "position": "7",
                      "level": "2",
                      "children": {
  
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>So in <code>doInBackground()</code>, I am doing as follows:-</p>
  
  <pre><code>@Override
  protected String doInBackground(String... params) {
  
      ServiceHandler serviceHandler = new ServiceHandler();
      String jsonStr = serviceHandler.makeServiceCall(
              Constants.SIDE_DRAWER_SERVICES, ServiceHandler.GET);
      try {
          JSONObject jobj = new JSONObject(jsonStr);
          Log.d("", "" + jsonStr.toString());
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return jsonStr;
  }
  </code></pre>
  
  <p>in String "jsonStr" i'm getting full data in response but when convert it into JSONObject like " JSONObject jobj = new JSONObject(jsonStr);" i'm getting missing of data like this:-</p>
  
  <pre><code>{
      "position": "0",
      "children": {
          "0": {
              "position": "1",
              "children": {
                  "3": {
                      "position": "4",
                      "children": {
  
                      },
                      "category_id": "35",
                      "level": "2",
                      "is_active": "1",
                      "name": "Offers",
                      "parent_id": "2"
                  },
                  "2": {
                      "position": "3",
                      "children": {
  
                      },
                      "category_id": "34",
                      "level": "2",
                      "is_active": "1",
                      "name": "Packages",
                      "parent_id": "2"
                  },
                  "1": {
                      "position": "2",
                      "children": {
  
                      },
                      "category_id": "33",
                      "level": "2",
                      "is_active": "1",
                      "name": "Memberships",
                      "parent_id": "2"
                  },
                  "0": {
                      "position": "1",
                      "children": {
                          "3": {
                              "position": "4",
                              "children": {
                                  "3": {
                                      "position": "4",
                                      "children": {
  
                                      },
                                      "category_id": "10",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Haircut",
                                      "parent_id": "7"
                                  },
                                  "2": {
                                      "position": "3",
                                      "children": {
  
                                      },
                                      "category_id": "9",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Hair Color",
                                      "parent_id": "7"
                                  },
                                  "1": {
                                      "position": "2",
                                      "children": {
  
                                      },
                                      "category_id": "42",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Hair Extensions",
                                      "parent_id": "7"
                                  },
                                  "0": {
                                      "position": "1",
                                      "children": {
  
                                      },
                                      "category_id": "8",
                                      "level": "4",
                                      "is_active": "0",
                                      "name": "Chemical Treatments",
                                      "parent_id": "7"
                                  },
                                  "7": {
                                      "position": "8",
                                      "children": {
  
                                      },
                                      "category_id": "14",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Other Hair Services",
                                      "parent_id": "7"
                                  },
                                  "6": {
                                      "position": "7",
                                      "children": {
  
                                      },
                                      "category_id": "13",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Hair Treatments",
                                      "parent_id": "7"
                                  },
                                  "5": {
                                      "position": "6",
                                      "children": {
  
                                      },
                                      "category_id": "12",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Hair Styling",
                                      "parent_id": "7"
                                  },
                                  "4": {
                                      "position": "5",
                                      "children": {
  
                                      },
                                      "category_id": "11",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Hair Straightening",
                                      "parent_id": "7"
                                  },
                                  "8": {
                                      "position": "9",
                                      "children": {
  
                                      },
                                      "category_id": "15",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Special Hair Services",
                                      "parent_id": "7"
                                  }
                              },
                              "category_id": "7",
                              "level": "3",
                              "is_active": "1",
                              "name": "Hair Services",
                              "parent_id": "32"
                          },
                          "2": {
                              "position": "3",
                              "children": {
                                  "2": {
                                      "position": "3",
                                      "children": {
  
                                      },
                                      "category_id": "6",
                                      "level": "4",
                                      "is_active": "1",
                                      "name": "Special Body Services",
                                      "parent_id": "3"
                                  },
                                  "1": {
                                      "position": "2",
                                      "children": {
  
                                      },
  </code></pre>
  
  <p>I don't know what is happening with my JSON. Please help me and tell me if JSON is invalid. </p>