I am having problem in parsing the following response. It contains n number os objects in an object with xml format. How should I parse them?
{
"000002": {
"ref": "000002",
"barcodes": {
"data": "<sku><barcode>000002014001</barcode><path></path><alias_code></alias_code><color>GREY</color><price>10.50</price><size>S</size><stock>0</stock></sku><sku><barcode>000002014002</barcode><path></path><alias_code></alias_code><color>GREY</color><price>10.50</price><size>M</size><stock>2</stock></sku><sku><barcode>000002014003</barcode><path></path><alias_code></alias_code><color>GREY</color><price>10.50</price><size>L</size><stock>1</stock></sku><sku>,
"#datatype": "xml"
}
},
"000012": {
"ref": "000012",
"barcodes": {
"data": "<sku><barcode>000012030001</barcode><path></path><alias_code></alias_code><color>BLUE</color><price>19.99</price><size>S</size><stock>1</stock></sku><sku><barcode>000012030002</barcode><path></path><alias_code></alias_code><color>BLUE</color><price>19.99</price><size>M</size><stock>3</stock></sku><sku>,
"#datatype": "xml"
}
},
"pager": {
"current_page": 1,
"start": 0,
"limit": 50,
"total": "354",
"pages": 8
}
}
I am trying the below parsing code, but it is throwing exceptions. parsing code:
ArrayList<Model_BarcodeDetail> group_list = null;
ArrayList<Model_BarcodeList_Child> child_list = null;
try {
group_list = new ArrayList<Model_BarcodeDetail>();
ResponseHandler<String> responseHandler = new BasicResponseHandler();
result = httpClient.execute(postRequest, responseHandler);
JSONObject jsonarray = new JSONObject(result);
for (int i = 0; i < jsonarray.length(); i++) {
child_list = new ArrayList<Model_BarcodeList_Child>();
JSONObject jsonObj = jsonarray.getJSONObject(i);
System.out.println("---json" + jsonObj);
Model_BarcodeDetail data = new Model_BarcodeDetail();
data.setReference((jsonObj.getString("ref")));
System.out.println("======refinprsing--"+data.getReference());
data.setName((jsonObj.getString("name")));
data.setDescription((jsonObj.getString("desc")));
data.setPrice((jsonObj.getString("price")));
data.setTotal(data.getPrice().trim());
data.setFixedTotal(data.getPrice().trim());
JSONArray obj2 = jsonObj.getJSONArray("skus");
for (int j = 0; j < obj2.length(); j++) {
JSONObject json = obj2.getJSONObject(j);
System.out.println("---json" + json);
Model_BarcodeList_Child data2 = new Model_BarcodeList_Child();
data2.setBarcode((json.getString("barcode")));
System.out.println("=======barcodeinparsing: "+data2.getBarcode());
data2.setColor((json.getString("color")));
data2.setSize((json.getString("size")));
data2.setPrice(json.getString("price"));
data2.setStock(json.getString("stock"));
data2.setAlis_code(json.getString("alias_code"));
child_list.add(data2);
}
data.setChildItems(child_list);
group_list.add(data);
}
} catch (Exception e) {
Log.i("Exception in DownloadBarcode method: ", e.getMessage());
return null;
}
return group_list;