1 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
Map map = new HashMap();
map.put( "name", "json" );
map.put( "bool", Boolean.TRUE );
map.put( "int", new Integer(1) );
map.put( "array", new String[]{"a","b"} );
map.put( "func", "function(i){ return this.arr[i]; }" );
JSONObject jsonObject = JSONObject.fromObject( map );
try {
List<Object> arr = jsonObject.names();//獲取名
Collection<Object> arra = jsonObject.values();//獲取值
for(Object name:arr){
System.out.println(name.toString());
}
for(Object value:arra){
System.out.println(value.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
添加回答
舉報(bào)