• JSON JAVA 总结


    1.如下是我所用json第三方jar包的maven坐标

     1 <!--可引用的jar-->
     2 <dependency>
     3 <groupId>net.sf.json-lib</groupId>
     4 <artifactId>json-lib</artifactId>
     5 <version>2.4</version>
     6 <classifier>jdk15</classifier>
     7 </dependency>
     8 <!--源码-->
     9 <dependency>
    10 <groupId>net.sf.json-lib</groupId>
    11 <artifactId>json-lib</artifactId>
    12 <version>2.4</version>
    13 <classifier>jdk15-sources</classifier>
    14 </dependency>

    2.JSONObject中常用的方法说明

     1 package cn.json;
     2 
     3 
     4 import net.sf.json.JSONObject;
     5 
     6 public class JsonDemo {
     7     private JSONObject json=new JSONObject();
     8     
     9     
    10     public static void main(String[] args) {
    11         new JsonDemo().put();
    12         /**<结果>
    13          * 对null对象的插入
    14          *  {"accumulate":null}
    15          * 对null字符串的插入
    16          * {"accumulate":[null,null],"element":null,"put":null}
    17          * 对字符串的插入
    18          * {"accumulate":[null,null,""],"element":"","put":""}
    19          * */ 
    20     }    
    21     
    22     /**
    23      * json的插入方法比较
    24      * 1.accumulate方法,可以对null对象插入,
    25      * 插入多个相同key的value值时,value将以插入顺序数组排列
    26      * 2.element 和 put 方法 插入 null对象 
    27      * 则这对key-value消失,插入多个相同的key-value,最终只保留最后一个
    28      */
    29     public void put(){
    30         System.out.println("对null对象的插入");
    31         String value=null;
    32         json.element("element",value);
    33         json.accumulate("accumulate", value);
    34         json.put("put", value);
    35         System.out.println(json);
    36         System.out.println("对null字符串的插入");
    37         value="null";
    38         json.element("element",value);
    39         json.accumulate("accumulate", value);
    40         json.put("put", value);
    41         System.out.println(json);
    42         System.out.println("对"+""+"字符串的插入");
    43         value="";
    44         json.element("element",value);
    45         json.accumulate("accumulate", value);
    46         json.put("put", value);
    47         System.out.println(json);
    48         
    49     };
    50     
    51 }
  • 相关阅读:
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    Ehcache(2.9.x)
    网站静态化处理—反向代理(10)
    网站静态化处理—满足静态化的前后端分离(9)
    网站静态化处理—前后端分离—下(8)
  • 原文地址:https://www.cnblogs.com/wangfeixiong/p/6597463.html
Copyright © 2020-2023  润新知