标签:new bean type color class map tle ring 转换
常用的json
list转json
List list=new ArrayList(); list.add("1"); list.add("2"); JsonArray json=JsonArray.fromObject(list);
map转json
Map map = new HashMap(); map.put("欧尼", "json"); map.put("听我", Boolean.TRUE); map.put("three", new Integer(1)); JSONObject json = JSONObject.fromObject(map);
Bean转换成json代码
JsonBean jb=new JsonBean() JSONObject jsonObject = JSONObject.fromObject(jb);
数组转换成json代码
int [] arr = new int[] { 1,2,3}; JSONArray jsonarray = JSONArray.fromObject(arr);
转换成json代码
JSONArray jsonarr = JSONArray.fromObject("[‘json‘,‘is‘,‘easy‘]" );
String jsonStr = "{\"id\": 2," +
" \"title\": \"json title\", " +
"\"config\": {" +
"\"name\": 34," +
"\"type\": 35," +
"}, \"class\": [" +
"\"one\", \"two\", \"three\"" +
"]}";
//转换成为JSONObject对象
JSONObject jsonObj = new JSONObject(jsonStr);
标签:new bean type color class map tle ring 转换
原文地址:http://www.cnblogs.com/xie-yi/p/6073244.html