博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从JSON数据中取出相关数据
阅读量:6939 次
发布时间:2019-06-27

本文共 822 字,大约阅读时间需要 2 分钟。

参考:

JSON数据如下:

{    "total": 1,    "rows": [        {            "id": "1",            "type": "1"        },        {            "id": "2",            "type": "2"        },      ]}

想要从上面的JSON数据中取出id,和type,可以使用如下方法

//获取待办信息环节    public void getData() throws Exception{       //获取到的json数据即如上面json数据        String json = this.getJson();             JSONObject object=JSONObject.fromObject(json);        JSONArray array = object.getJSONArray("rows");        String id1 ="";       String type1 = "";     String id2 ="";       String type2 = "";        if(array.size()>1){            Map map = (Map) array.get(0);            id1 = (String)map.get("id");       type1 = (String)map.get("type");            id2 = (String)map.get("id");       type2 = (String)map.get("type");        }    }

以上方法从上面json数据中取到了所需数据。

此方式可以从JSON数据中取到所需数据。

转载地址:http://lsfnl.baihongyu.com/

你可能感兴趣的文章