我試圖挽救服務器的響應,但我得到的例外.. 這是響應:異常節省JSON
[
{
"MediEazyInvoiceitemsList": [
{
"Id": 1,
"MediEazyInvoiceId": 1,
"ProductId": 1,
"ManufacturerId": null,
"ProductName": "Crocef (500 mg)",
"ScheduleType": "H",
"Quantity": 2,
"Dosage": "1-0-1"
},
{
"Id": 2,
"MediEazyInvoiceId": 1,
"ProductId": 1,
"ManufacturerId": null,
"ProductName": "Dispar (300 mg)",
"ScheduleType": "H",
"Quantity": 5,
"Dosage": "1-0-1"
}
],
"Id": 1,
"CustomerId": 5,
"PharmacyId": 1,
"Customer": null,
"DeliveryAddress": "sfh, ghh",
"CustomerLatitude": "24.9876",
"CustomerLongitude": "72.0987",
"OrderStatus": 0,
"Remarks": null,
"Comments": null,
"Instructions": "Testing",
"Prescription": null,
"PrescriptionPath": ""
},
{
"MediEazyInvoiceitemsList": [
{
"Id": 3,
"MediEazyInvoiceId": 2,
"ProductId": 1,
"ManufacturerId": null,
"ProductName": "Crocin (15 ml)",
"ScheduleType": "H",
"Quantity": 1,
"Dosage": "1-0-1"
},
{
"Id": 4,
"MediEazyInvoiceId": 2,
"ProductId": 1,
"ManufacturerId": null,
"ProductName": "Dispar (300 mg)",
"ScheduleType": "H",
"Quantity": 5,
"Dosage": "1-0-1"
}
],
"Id": 2,
"CustomerId": 5,
"PharmacyId": 1,
"Customer": null,
"DeliveryAddress": "sfh, ghh",
"CustomerLatitude": "24.9876",
"CustomerLongitude": "72.0987",
"OrderStatus": 0,
"Remarks": null,
"Comments": null,
"Instructions": "Testing",
"Prescription": null,
"PrescriptionPath": ""
}]
我救不了這一點。我試圖爲:
String result = Utils.convertInputStreamToString(inputStream);
//Printing server response
System.out.println("server response is :" + result + "\n" + inputStream);
try {
JSONObject jsonObject=new JSONObject();
JSONObject jo=jsonObject.getJSONObject("");
ja=jo.getJSONArray("MediEazyInvoiceitemsList");
// checking if server response is successful
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
這是我收到的錯誤:
05-29 17:53:51.714: W/System.err(8891): org.json.JSONException: No value for MediEazyInvoiceItemsList
我有這麼多的陣列真的很困惑和對象請大家幫忙,thnxx
的JSONObject的JSONObject =新的JSONObject();應該是JSONObject jsonObject = new JSONObject(myStringVariableWithJSONData); –
'JSONObject jsonObject = new JSONObject(response);' –
我不知道myStringVariableWithJSONData ... – Prakhar