How To Parse Nested Json Object Using The Json Library?
i want to parse the json object using json library. { 'batters': { 'batter': [ { 'id': '1001', 'type': 'Regular' },
Solution 1:
Using JSON..
JSONObjectobject = newJSONObject(yourString);
JSONObject batters = object.getJSONObject("batters");
JSONArray batter = batters.getJSONArray("batter");
for(int i = 0 ; i < batter.length() ; i++) {
JSONObject object1 = (JSONObject) batter.get(i);
String id = object1.getString("id");
}
Solution 2:
{"result":"success","countryCodeList":[{"countryCode":"00","countryName":"World Wide"},{"countryCode":"kr","countryName":"Korea"}]}
Here below I am fetching country details
JSONObject json = newJSONObject(jsonstring);
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
JSONArray valArray1 = valArray.getJSONArray(1);
valArray1.toString().replace("[", "");
valArray1.toString().replace("]", "");
int len = valArray1.length();
for (int i = 0; i < valArray1.length(); i++) {
Country country = newCountry();
JSONObject arr = valArray1.getJSONObject(i);
country.setCountryCode(arr.getString("countryCode"));
country.setCountryName(arr.getString("countryName"));
arrCountries.add(country);
}
Post a Comment for "How To Parse Nested Json Object Using The Json Library?"