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

JSON与JAVA的数据转换-Map

热度:112   发布时间:2012-10-24 14:15:58.0
JSON与JAVA的数据转换--Map
2、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 );       
 //{"func":function(i){ return this.arr[i]; },"arr":["a","b"],"int":1,"name":"json","bool":true}    
 
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 );     
 //{"func":function(i){ return this.arr[i]; },"arr":["a","b"],"int":1,"name":"json","bool":true} 
  相关解决方案