首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JSON与JAVA的数据转换-Map

2012-10-24 
JSON与JAVA的数据转换--Map2、Map Map map  new HashMap()       map.put( name, json )       map.

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} 

热点排行