JSON字符串相关转换

来源:互联网 发布:淘宝联盟官方群 编辑:程序博客网 时间:2024/06/06 00:37

第一种

[    {        "id":"25",        "ownerId":"",        "tagKey":"播种",        "tagPhoto":"eee",        "createTime":"2017-06-21 11:16:57.0",        "updateTime":"2017-06-21 11:16:59.0"    },    {        "id":"82815d29-2346-4790-9df0-f336916e7e96",        "ownerId":"",        "tagKey":"施肥",        "tagPhoto":"redd",        "createTime":"2017-06-21 14:27:00.0",        "updateTime":"2017-06-21 14:27:02.0"    }]

转换

@Overridepublic void onSuccess(String s, boolean fromCache) throws Exception {    defTab = new ArrayList();    JSONArray jsonArray = new JSONArray(s);    for (int i=0;i<jsonArray.length();i++){        Tab tab = JSON.parseObject(jsonArray.getString(i),Tab.class);        defTab.add(tab);    }}











第二种

带分页的

{    "pageIndex":1,    "pageSize":3,    "totalPages":450,    "totalCount":1348,    "data": [        {            "id":"01af2f15-63d2-457d-b807-1cf84047124d",            "farmName":"德江桶井场坝村思源脐橙专业合作社"        },        {            "id":"02949083-55fc-4baa-8b2e-801634703c60",            "farmName":"石阡红薯干"        },        {            "id":"02bf7c21-08c3-4320-bcb7-971da5b40e23",            "farmName":"1"        }    ]}

转换

 @Override    public void onSuccess(String s, Call call, Response response) {        try {            JSONObject jsonObject = new JSONObject(s);            pageTotalCount = jsonObject.getInt("totalPages");            JSONArray datas = jsonObject.getJSONArray("data");            for (int i = 0; i < datas.length(); i++) {                EmployeeItem item = JSON.parseObject(datas.getString(i), EmployeeItem.class);                employeeData.add(item);            }        } catch (JSONException e) {            e.printStackTrace();        }    }});



原创粉丝点击