Ich analysiere die folgende JSON-Antwort, aber es gibt ein Problem beim Parsen, der Code, den ich versuche, analysiert nicht und ich bekomme keine Ausnahme oder Antwort.Wie analysiert man Array von Objekten in Android
Der Code, den ich beantragt hatte, es zu analysieren ist:
ArrayList<Model_BarcodeDetail> DownloadBarcode(String api_token) {
ArrayList<Model_BarcodeDetail> barcodeList = new ArrayList<Model_BarcodeDetail>();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(Utility.BASE_URL
+ "?q=webservice/barcode_list&token=" + api_token +"&page="+"1"
+ "&return=json");
String url = Utility.BASE_URL
+ "?q=webservice/barcode_list&token=" + api_token +"&page="+"1"
+ "&return=json";
System.out.println("======url::"+url);
String result = "";
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 root = new JSONObject(result);
JSONObject obj = root.getJSONObject("");
System.out.println("====objjjj: "+obj.toString());
JSONArray arraylist=obj.names();
for (int i = 0; i < arraylist.length(); i++) {
child_list = new ArrayList<Model_BarcodeList_Child>();
JSONObject jsonObj = arraylist.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("barcodes");
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);
}
for (int k = 0; k < group_list.size(); k++) {
System.out.println("-----==data itemref "
+ group_list.get(k).getReference());
for (int y = 0; y < group_list.get(k).getChildItems().size(); y++) {
System.out.println("-----====data color "
+ group_list.get(k).getChildItems().get(y)
.getColor());
}
}
} catch (Exception e) {
Log.i("Exception in DownloadBarcodechanges method: ", e.getMessage());
return null;
}
return group_list;
}
Hier die json ist:
{
"000002": {
"ref": "000002",
"barcodes": [
{
"barcode": "000002014001",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "S",
"stock": "0"
},
{
"barcode": "000002014002",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "M",
"stock": "2"
},
{
"barcode": "000002014003",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "L",
"stock": "1"
},
{
"barcode": "000002014004",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "XL",
"stock": "0"
},
{
"barcode": "000002014005",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "XXL",
"stock": "1"
},
{
"barcode": "000002014006",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "13.50",
"size": "2XL",
"stock": "3"
},
{
"barcode": "000002014007",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "13.50",
"size": "3XL",
"stock": "5"
},
{
"barcode": "000002014008",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "13.50",
"size": "4XL",
"stock": "6"
},
{
"barcode": "000002014009",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "13.50",
"size": "5XL",
"stock": "5"
},
{
"barcode": "000002014010",
"path": null,
"alias_code": null,
"color": "GREY",
"price": "10.50",
"size": "6XL",
"stock": "2"
}
]
},
"000012": {
"ref": "000012",
"barcodes": [
{
"barcode": "000012030001",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "S",
"stock": "1"
},
{
"barcode": "000012030002",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "M",
"stock": "3"
},
{
"barcode": "000012030003",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "L",
"stock": "4"
},
{
"barcode": "000012030004",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "XL",
"stock": "2"
},
{
"barcode": "000012030005",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "XXL",
"stock": "0"
},
{
"barcode": "000012030006",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "2XL",
"stock": "0"
},
{
"barcode": "000012030007",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "3XL",
"stock": "0"
},
{
"barcode": "000012030008",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "4XL",
"stock": "0"
},
{
"barcode": "000012030009",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "5XL",
"stock": "0"
},
{
"barcode": "000012030010",
"path": null,
"alias_code": null,
"color": "BLUE",
"price": "19.99",
"size": "6XL",
"stock": "0"
}
]
},
"pager": {
"current_page": 1,
"start": 0,
"limit": 50,
"total": "354",
"pages": 8
}
}
Was ist diese Linie? JSONObject obj = root.getJSONObject (""); – user6547359
ich kann nicht finden "ref", "farbe", "größe", "stock" etc in ihrem link .. überprüfen sie es einmal .. !! –
Warum gibt es in Ihrem JSONObject null? – Zartha