I have a Json array which contains another array. I want to fetch the data of second array.ie: In my case "Material code". Please forgive me if I asked a repeated question.
My Json
{
"Result": true,
"Records": {
"ID": "37e33c9e",
"RRNo": "RR301",
"Title": "rightnow",
"RRDate": "2018-06-27T00:00:00",
"RRForCompany": "A",
"RRStatus": "Open",
"RRDetailList": [{
"ID": "dff49a5a",
"RRID": "37e33c9e",
"MaterialID": "b4378594",
"Description": "Pol",
"ExtendedDescription": "hello",
"CurrStock": "10",
"ApRate": 2000.00,
"RequestedQty": "8100",
"RRMaterialObj": {
"ID": "b4378594",
"MaterialCode": "R101",
"ApRate": 0.0,
}
}],
"CompanyObj": null,
"CommonObj": {
},
"RRFormatted": "27-Jun-2018",
}
}
What i have done
ArrayList<String[]> dataArrayList=new ArrayList<>();
JSONArray jsonObject1= records.getJSONArray("RRDetailList");
for (int i = 0; i < jsonObject1.length(); i++) {
JSONObject jsonObject2 = jsonObject1.getJSONObject(i);
String[] data = new String[6];
data[0] = jsonObject2.getString("ID");
data[1] = jsonObject2.getString("Description");
data[2] = jsonObject2.getString("RequestedQty");
data[3] = jsonObject2.getString("CurrStock");
data[4] = jsonObject2.getString("ApRate");
JSONArray jsonObject3 = records.getJSONArray("RRMaterialObj");
for(int j=0;j<jsonObject3.length();j++){
JSONObject jsonObject5= jsonObject3.getJSONObject(j);
data[5] =jsonObject5.getString("MaterialCode");
}
dataArrayList.add(data);
}
Help me. Iam newbie to android.