I've got problem with parsing JSON. I've got response from webservice like this :
{
"data": {
"1": [
{
"id": "2",
"name": "Szelki bezpieczeństwa",
"quantity": "1",
"note": null,
"picture_id": null,
"code": "CCCCCCCCCCCCCC"
},
{
"id": "3",
"name": "Kalosze do brodzenia, wysokie lub biodrowe",
"quantity": "2",
"note": "Do wymiany",
"picture_id": null,
"code": "DDDDDDDDDDDDDD"
}
],
"2": [
{
"id": "1",
"name": "Spodnie dla pilarza z ochroną przed przecięciem, klasa min. 1 (wg PN-EN 381-5)",
"quantity": "2",
"note": "Uszkodzone",
"picture_id": null,
"code": "DAAD086F690E1C36"
}
]
}
}
I try to parse it into PART object and add it to List but somewhere I'm making mistake because object is not being parsed.
public void onResponse(String response) {
Log.e(TAG, "onResponse WHOLE: " + response);
try {
JSONObject responseJSONObject = new JSONObject(response);
String arrayString = responseJSONObject.getJSONArray("data").toString();
JSONArray responseJSONArray = new JSONArray(arrayString);
Part tempCarEquipment;
int index = 1;
for (int i = 0; i < responseJSONArray.length(); i++,index++) {
JSONObject object = responseJSONArray.getJSONObject(index);
JSONArray response2 = object.getJSONArray(Integer.toString(index));
String id = object.getJSONObject(Integer.toString(i)).getString("id");
String name= object.getJSONObject(Integer.toString(i)).getString("name");
String quantity= object.getJSONObject(Integer.toString(i)).getString("quantity");
String picture_id= object.getJSONObject(Integer.toString(i)).getString("picture_id");
String code= object.getJSONObject(Integer.toString(i)).getString("code");
tempCarEquipment = new Part(name,quantity,"",picture_id,code,id,"",0);
wholeList.add(tempCarEquipment);
Log.e(TAG, "wholeList: " + wholeList.size());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Thanks in advance fo every help! :)