文件名称:json-lib完整架包
文件大小:984KB
文件格式:ZIP
更新时间:2016-09-05 07:45:48
json-lib
@Test public void testArrayToJSON(){ boolean[] boolArray = new boolean[]{true,false,true}; JSONArray jsonArray = JSONArray.fromObject( boolArray ); System.out.println( jsonArray ); // prints [true,false,true] } //Collection对象转换成JSON @Test public void testListToJSON(){ List list = new ArrayList(); list.add( "first" ); list.add( "second" ); JSONArray jsonArray = JSONArray.fromObject( list ); System.out.println( jsonArray ); // prints ["first","second"] } //字符串json转换成json, 根据情况是用JSONArray或JSONObject @Test public void testJsonStrToJSON(){ JSONArray jsonArray = JSONArray.fromObject( "['json','is','easy']" ); System.out.println( jsonArray ); // prints ["json","is","easy"] } //Map转换成json, 是用jsonObject @Test public void testMapToJSON(){ 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 jsonObject = JSONObject.fromObject( map ); System.out.println( jsonObject ); } //复合类型bean转成成json @Test public void testBeadToJSON(){ MyBean bean = new MyBean(); bean.setId("001"); bean.setName("银行卡"); bean.setDate(new Date()); List cardNum = new ArrayList(); cardNum.add("农行"); cardNum.add("工行"); cardNum.add("建行"); cardNum.add(new Person("test")); bean.setCardNum(cardNum); JSONObject jsonObject = JSONObject.fromObject(bean); System.out.println(jsonObject); }
【文件预览】:
json-lib
----ezmorph-1.0.2.jar(76KB)
----commons-beanutils.jar(116KB)
----commons-collections-3.0.jar(506KB)
----commons-lang-2.1.jar(203KB)
----commons-logging.jar(31KB)
----xom-1.0d10.jar(104KB)
----json-lib-1.1-jdk13.jar(65KB)