关键字: json java
JSON-lib这个Java类包用于把bean,map和XML转换成JSON并能够把JSON转回成bean和DynaBean。

下载地址:http://json-lib.sourceforge.net/
还要需要的第3方包:
org.apache.commons(3.2以上版本)
org.apache.oro
net.sf.ezmorph(ezmorph-1.0.4.jar)
nu.xom

1、List
Java代码
  1. boolean[] boolArray = new boolean[]{true,false,true};
  2. JSONArray jsonArray1 = JSONArray.fromObject( boolArray );
  3. System.out.println( jsonArray1 );
  4. // prints [true,false,true]
  5. List list = new ArrayList();
  6. list.add( "first" );
  7. list.add( "second" );
  8. JSONArray jsonArray2 = JSONArray.fromObject( list );
  9. System.out.println( jsonArray2 );
  10. // prints ["first","second"]
  11. JSONArray jsonArray3 = JSONArray.fromObject( "['json','is','easy']" );
  12. System.out.println( jsonArray3 );
  13. // prints ["json","is","easy"]
boolean[] boolArray = new boolean[]{true,false,true};
JSONArray jsonArray1 = JSONArray.fromObject( boolArray );
System.out.println( jsonArray1 );
// prints [true,false,true]
List list = new ArrayList();
list.add( "first" );
list.add( "second" );
JSONArray jsonArray2 = JSONArray.fromObject( list );
System.out.println( jsonArray2 );
// prints ["first","second"]
JSONArray jsonArray3 = JSONArray.fromObject( "['json','is','easy']" );
System.out.println( jsonArray3 );
// prints ["json","is","easy"]

2、Map
Java代码
  1. Map map = new HashMap();
  2. map.put( "name", "json" );
  3. map.put( "bool", Boolean.TRUE );
  4. map.put( "int", new Integer(1) );
  5. map.put(