android Json数据解析

 

JSONObject jsonObject = new JSONObject(jsonutil.json);   // jsonutil.json  接收到服务端传递的数据
   JSONArray jsonArray = jsonObject.getJSONArray("list_allFoods");  //服务端的List数组名
   for (int y = 0; y < jsonArray.length(); y++) {  
   

     //数组接收方法

    JSONObject json = (JSONObject) jsonArray.get(y);  //y 为数组下标 0,1,2......
    json.getString("属性名");

 

    //数组中的对象接收方法

    JSONObject food = json.getJSONObject("对象名");
    JSONObject user = json.getJSONObject("对象名");

    food.getString("属性名");

 

 

}

 可将json数据存于字符串 或者 List<Object> 中 方便使用

posted @ 2012-10-31 19:46  晓晓軍  阅读(192)  评论(0)    收藏  举报