国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
使用json-lib 數(shù)據(jù)格式轉(zhuǎn)換
使用json-lib 數(shù)據(jù)格式轉(zhuǎn)換

下載

    http://json-lib.sourceforge.net下載json-lib-1.1-jdk15.jar,運行json還需要的包有:commons-lang.jar、commons-logging.jar,commons-beanutils.jar、xom-1.0-2005-01-05.jar、ezmorph-1.0.1.jar,可在http://www.docjar.com搜索下載。

   

l         轉(zhuǎn)化數(shù)組和集合

    boolean[] boolArray = new boolean[]{true,false,true};

       JSONArray jsonArray = JSONArray.fromObject(boolArray);

       System.out.println(jsonArray);

    輸出:[true,false,true]

    List list = new ArrayList();

       list.add(“第一個”);

       list.add(“第二個”);

       JSONArray jsonArray = JSONArray.fromObject(list);

    System.out.println(jsonArray);

    輸出:[“第一個”, “第二個”]

      

       JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']");

    System.out.println(jsonArray3);

    輸出:[“json”, “is”, “'easy'”]

l         轉(zhuǎn)化對象

轉(zhuǎn)化Map

Map map = new HashMap();

map.put("name","json");

map.put("bool",Boolean.TRUE);

map.put("int",new Integer(1));

map.put("arr",new String[]{"a","b"});

map.put("func","function(i){return this.arr[i];}");

JSONObject json = JSONObject.fromObject(map);

System.out.println(json);

輸出:[“name”: “json”, “bool”:true, “int”,1, “arr”:[ “a”, “b”], “func”:function(i){return this.arr[i];}]

轉(zhuǎn)化Bean

MyBean.java

public class MyBean {

    private String name = "json";

    private int pojoId = 1;

    private String func1 = "function(i){return this.options[i]}";

    private JSONFunction func2 = new JSONFunction(new String[]{"i"},"return this.options[i];");

   

    //以下為get、set方法

}

MyBean bean = new MyBean();

JSONObject jsonObject = JSONObject.fromObject(bean);

System.out.println(jsonObject);

輸出:

{"func1":function(i){return this.options[i]},"pojoId":1,"name":"json","func2":function(i){ return this.options[i]; }

JSONBeans

//轉(zhuǎn)化為動態(tài)bean

String myjson = "{name=""json"",bool:true,int:1,double:2.2,function:function(a){return a;},array:[1,2]}";

JSONObject json1 = JSONObject.fromString(myjson);

Object bean1 = JSONObject.toBean(json1);

JSON生成XML

JSONObject json = new JSONObject(true);

XMLSerializer xmlSerializer = new XMLSerializer();

String xml = xmlSerializer.write(json);

System.out.println("xml:" + xml);

輸出:xml:<?xml version="1.0" encoding="UTF-8"?>

<o null="true"/>

JSONObject json2 = JSONObject.fromObject("{""name"":""json"",""bool"":true,""int"":1}");

String xml2 = xmlSerializer.write(json2);

System.out.println("xml2:" + xml2);

輸出:xml2:<?xml version="1.0" encoding="UTF-8"?>

<o><bool type="boolean">true</bool><int type="number">1</int><name type="string">json</name></o>

JSONArray json3 = JSONArray.fromObject("[1,2,3]");

String xml3 = xmlSerializer.write(json3);

System.out.println("xml3:" + xml3);

輸出:xml3:<?xml version="1.0" encoding="UTF-8"?>

<a><e type="number">1</e><e type="number">2</e><e type="number">3</e></a>

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
json lib使用教程
JSON與JAVA數(shù)據(jù)的轉(zhuǎn)換
JSON----json_lib.jar
JSON:Java--解析(讀取)Json數(shù)據(jù)
JSON-lib框架,轉(zhuǎn)換JSON、XML不再困難
使用HttpClient通過post方式發(fā)送json數(shù)據(jù)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服