当前位置: 代码迷 >> JavaScript >> JSON与JAVA的数据转换-list
  详细解决方案

JSON与JAVA的数据转换-list

热度:146   发布时间:2012-11-23 00:03:43.0
JSON与JAVA的数据转换--list
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
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"]       
 
 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"]     
  相关解决方案