数组型Json 解析

来源:互联网 发布:老司机网址知乎 编辑:程序博客网 时间:2024/06/08 20:18


[{"img1":"http://172.17.29.120/localuser/ljy/shop/bannerpic/201407310157304712_x.jpg","img2":"http://172.17.29.120/localuser/ljy/shop/bannerpic/1458525609380.jpg","img3":"http://172.17.29.120/localuser/ljy/shop/bannerpic/20130428084719999.jpg"}]

手动解析

try {

                    System.out.println("result----->" + result);

                    JSONArray jsonArray;

                    jsonArray = new JSONArray(result);

                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        String img1 = jsonObject.getString("img1");
                        String img2 = jsonObject.getString("img2");
                        String img3 = jsonObject.getString("img3");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();

                }

Gson架包解析

    Gson gson = new Gson();
                Bean1[] fromJson = gson.fromJson(result, Bean1[].class);
                System.out.println("--------" + fromJson[0].getIma());

2 0