I have json object with this structure.
{
"count": 3,
"result": {
"1": {
"brand_id": "1",
"brand_name": "Adidas",
"brand_image": "http://a.jpg"
},
"2": {
"brand_id": "2",
"brand_name": "Asics",
"brand_image": "http: //b.jpg"
},
"3": {
"brand_id": "3",
"brand_name": "Adidas adidas",
"brand_image": "http: //c.jpg"
}
}
}
This is not a static one. Count may vary.
I have tried like this. I don't want to use gson. I want to parse in this. How to proceed with such a structure of data.
JSONObject totalData=new JSONObject(results.toString());
JSONObject brandResults=totalData.getJSONObject("result");
// I can get output in this.
Log.e("Result output", brandResults.toString());
// this is not working
int brandCounts = brandResults.getInt("count");
Log.e("BRAND COUNTS", ""+brandCounts);
if (brandCounts > 0) {
for (int i = 0; i < brandCounts; i++) {
JSONObject items = brandResults.getJSONObject(Integer.toString(i));
String brand_id=items.getString("brand_id");
Log.e("Brand id", brand_id);
}
}