I am trying to save the response from server but I am getting exception.. This is the response:
[
{
"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": ""
}]
I can't save this. What I am trying is:
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();
}
This is the error I am getting:
05-29 17:53:51.714: W/System.err(8891): org.json.JSONException: No value for MediEazyInvoiceItemsList
I am really confused with so many arrays and objects please help, thnxx
JSONObject jsonObject=new JSONObject(response);