I have A JSON where I am getting "Floor", "flat_no" and "Flat_id". So I am getting them like this.
{
"results": [
{
"Flat_id": "1",
"cat": "2",
"Flat_no": "101",
"Floor": "1",
"Flat_type": "1 bhk",
},
{
"Flat_id": "2",
"cat": "2",
"Flat_no": "102",
"Floor": "1",
"Flat_type": "2 bhk",
},
{
"Flat_id": "3",
"cat": "2",
"Flat_no": "103",
"Floor": "1",
"Flat_type": "3 bhk",
},
{
"Flat_id": "4",
"cat": "2",
"Flat_no": "104",
"Floor": "1",
"Flat_type": "1 rk",
},
{
"Flat_id": "5",
"cat": "2",
"Flat_no": "201",
"Floor": "2",
"Flat_type": "1 bhk",
"Floor plan": "http://vaserp.com/floor_plan/img1_1157img1_354454.png"
},
{
"Flat_id": "6",
"cat": "2",
"Flat_no": "202",
"Floor": "2",
"Flat_type": "2 bhk",
"Floor plan": "http://vaserp.com/floor_plan/img1_218706img1_1188632.png"
},
{
"Flat_id": "7",
"cat": "2",
"Flat_no": "203",
"Floor": "2",
"Flat_type": "3 bhk",
},
{
"Flat_id": "8",
"cat": "2",
"Flat_no": "204",
"Floor": "2",
"Flat_type": "1 rk",
}
]
}
I know JSON parsing. But I need A "Floor", and after that all flat and their id of that particular "Floor". I've attached an image, which show how I need to show the data ? Where "22" is floor and "201 to 205" are flat no. So please help me how can I sort this problem ?
I tried like this
try {
JSONObject jsonObj = new JSONObject(jsonStr);
allFloorDetailArray = jsonObj.getJSONArray(JSONUrl.TAG_RESULT);
for (int i = 0; i < allFloorDetailArray.length(); i++) {
JSONObject c = allFloorDetailArray.getJSONObject(i);
FloorDetailItem floorDetailItem = new FloorDetailItem();
floorDetailItem.setCat(c.getString(JSONUrl.TAG_CAT));
floorDetailItem.setFlatNo(c.getString(JSONUrl.TAG_FLAT_NO));
floorDetailItem.setFloor(c.getString(JSONUrl.TAG_FLOOR));
floorNo = c.getString(JSONUrl.TAG_FLOOR);
floorDetailItem.setFlatType(c.getString(JSONUrl.TAG_FLATE_TYPE));
floorDetailItem.setFloorPlanImage(c.getString(JSONUrl.TAG_FLOOR_PLAN));
mListDetailFloor.add(floorDetailItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
