我有一个包含另一个数组的Json数组。我想获取第二个array.ie的数据:以我的情况为“材料代码”。如果我再问一次,请原谅我。
我的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",
}
}
我做了什么
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);
}
帮帮我。我是新手,还是Android。
答案 0 :(得分:1)
records.getJSONArray("RRMaterialObj")
更改为
`jsonObject2.getJSONObject("RRMaterialObj");`
JSONObject jsonObject3 = jsonObject2.getJSONArray("RRMaterialObj");
data[5] =jsonObject3.getString("MaterialCode");