JSON JAVA 總結

來源:互聯網
上載者:User

標籤:json-lib   stat   引用   artifact   element   nbsp   style   數組   字串   

如下是我所用json第三方jar包的maven座標:

<!--可引用的jar--><dependency><groupId>net.sf.json-lib</groupId><artifactId>json-lib</artifactId><version>2.4</version><classifier>jdk15</classifier></dependency><!--源碼--><dependency><groupId>net.sf.json-lib</groupId><artifactId>json-lib</artifactId><version>2.4</version><classifier>jdk15-sources</classifier></dependency>
View Code

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 }
View Code

 

JSON JAVA 總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.