JSONObject用法

JSONObject

取字符串getString

转JSONObject 对:JSON.parseObject

JSONObject jsonObjectTemplate = yunzhijiaUtils.getTemplateByCodeId(param5);
String data = jsonObjectTemplate.getString("data");
JSONObject dataObj =JSON.parseObject(data);
String basicInfo =dataObj.getString("basicInfo");
JSONObject basicInfoObj =JSON.parseObject(basicInfo);
String formDefId = basicInfoObj.getString("formDefId");

JSONObject jsonObject = JSON.parseObject(res);
        String data = jsonObject.getString("data");
        JSONObject jsonObjects = JSON.parseObject(data);
        JSONArray ja = jsonObjects.getJSONArray("rows");
        for (int i = 0; i < ja.size(); i++) {
            JSONObject jo = ja.getJSONObject(i);
            String op_way = jo.getString("op_way");
            String op_time = jo.getString("op_time");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long lt = new Long(op_time);
            Date date = new Date(lt);
            res = simpleDateFormat.format(date);
            String pwd_no = jo.getString("pwd_no");
            String user_mobile = jo.getString("user_mobile");
            System.out.println(op_way + res + pwd_no + user_mobile + "------------");
        }
————————————————
版权声明:本文为CSDN博主「修仙ing~」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/kxj19980524/article/details/83718971

 JSONArray widgetValue = JSONArray.fromObject(widgetValueStr);

<!--json数组,字符串转换-->
<dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.4</version>
    <classifier>jdk15</classifier>
</dependency>

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

使用:

JSONArray array = JSONArray.fromObject("JSON数组字符串");

JSONObject jsonObject = JSONObject.fromObject("JSON格式字符串");

如:

{
        "type":2,
        "name":"222",
        "content":{
            "title":"222",
            "list":[
                {"title":"222","content":"222"},
                {"title":"222","content":"22222 33333 44444"}
            ]}
 }

原文地址:https://www.cnblogs.com/gzhbk/p/12651602.html