我有以下json。
for (var key in post) {
var one = post[key];
console.log(one);
break;
}
我使用volley获取json响应。像 {
"status": 1,
"value": {
"details": [
{
"shipment_no": "60178000059574",
"shipment_ref_no": "VAPL/EXP/19",
"proforma_invoice_no": "IN-70054000065076",
"proforma_invoice_date": "06-FEB-16",
"planned_shipment_date": "",
"point_of_contact": {
"empid": "60097000005728"
},
"products": {
"0": "Coco Peat Low EC"
},
"quantity": {
"0": "48 Pallets"
},
"rate": {ac
"0": "215 MTS"
},
"amount": {
"0": "617136"
},
"product_image": {
"0": "http://localhost/bogi/export/ver-1/images/employee/Desert.jpg"
},
"status": "3"
},
{
"shipment_no": "50108000007144",
"shipment_ref_no": "VAPL/EXP/46/14-15",
"proforma_invoice_no": "in-VAPL/EXP/46/14-15",
"proforma_invoice_date": "03-FEB-16",
"planned_shipment_date": "",
"point_of_contact": {
"empid": "60162000009888"
},
"products": {
"0": "MAIZE/CORN STARCH"
},
"quantity": {
"0": "38 PP Bags"
},
"rate": {
"0": "429 MTS"
},
"amount": {
"0": "1002409.98"
},
"product_image": {
"0": "http://localhost/bogi/noimage.jpg"
},
"status": "5"
},
{
"shipment_no": "60178000059574",
"shipment_ref_no": "VAPL/EXP/120/15-16",
"proforma_invoice_no": "in-123",
"proforma_invoice_date": "02-FEB-16",
"planned_shipment_date": "",
"point_of_contact": {
"empid": "60097000005728"
},
"products": {
"0": "Coco Peat Low EC"
},
"quantity": {
"0": "115 Pallets"
},
"rate": {
"0": "267 MTS"
},
"amount": {
"0": "2041882.5"
},
"product_image": {
"0": "http://localhost/bogi/Desert.jpg"
},
"status": "5"
}
]
}
}
Following is my code to parse json.
for (int i = 0; i < numberOfItems; i++) {
JSONObject jsonObjects = details.getJSONObject(i);
String shipmentNo = jsonObjects.getString("shipment_no");
JSONObject empId = jsonObject.getJSONObject("point_of_contact");
JSONObject productId = jsonObject.getJSONObject("products");
Iterator<String> iterator = empId.keys();
Iterator<String> productIterator = productId.keys();
while (iterator.hasNext()){
String key = iterator.next();
Log.d(TAG,empId.optString(key));
}
while (productIterator.hasNext()){
String key = iterator.next();
Log.d(TAG,.optString(key));
}
}
这样的键和emp_id
中的键是动态的。因此,我遍历json以获取键和值。但是,它会抛出一条错误消息products
和no value exists for pointOfContact
。为什么我会收到此错误?