zoukankan      html  css  js  c++  java
  • 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"}
                ]}
     }

  • 相关阅读:
    PHP 多参数方法的重构
    PHP cURL库函数抓取页面内容
    PHP下载远程文件到指定目录
    PHP生成特定长度的纯字母字符串
    PHP提取奇数或偶数下标元素
    Java中的clone()----深复制,浅复制
    LeetCode题解 343.Integer Break
    MySQL学习笔记(四):存储引擎的选择
    存储过程优缺点
    MySQL学习笔记(三):常用函数
  • 原文地址:https://www.cnblogs.com/gzhbk/p/12651602.html
Copyright © 2011-2022 走看看