-5

如何解析下面的json。

    [
    {
        "products": [
            {
                "description": "USB2.0. 1000 dpi, Double Lens Technology. Black  
           (Red,Orange.Green.Grey),White(Red,Orange.Green,Grey) 
             <\/p>",
                "product_id": "36",
                "name": "New      
            MP-770",
                "product_code": "MO018",
                "images": "productimage\/36",
                "price": "59900",
                "weight": "1.00"
            }
        ],
        "num_page": 1
    }
]
4

2 回答 2

0

您可以使用 JsonObject/JsonArray 中的 Android Build 来完成,也可以使用 Google 的一个名为GSON的库。 看看这两个教程:GOOGLE和这个ONE

但是下次请使用google,有成千上万的教程向您解释

于 2013-10-09T07:29:55.903 回答
0
JSONArray json = jParser.getJSONFromUrl(URL);

try {
    JSONObject c = json.getJSONObject(0);
JSONArray json1  = c.getJSONArray("products");                      
status = c.getString("num_page"); 

for(int i=0;i<json1.length();i++){

    JSONObject c1 = json1.getJSONObject(i);
    String des = c1.getString("description");
    String pid = c1.getString("product_id");
    String name = c1.getString("name");
    String pc = c1.getString("product_code");
    String images = c1.getString("images");
    String price = c1.getString("price");
    String weight = c1.getString("weight");

    // creating new HashMap
    HashMap<String, String> map = new HashMap<String, String>();

    // adding each child node to HashMap key => value
    map.put("description", des);
    map.put("product_id", pid);
    map.put("name", name);
    map.put("product_code",pc);
    map.put("images", images);
    map.put("price", price);
    map.put("weight", weight);                         

    fetch.add(map);
}

复制粘贴代码并使用它, fetch 是您的 hashmap 数组列表,如果任何问题仍然存在,请告诉我。

于 2013-10-09T08:10:52.373 回答