//Map转换成JSON
Mapmap = new HashMap (); map.put("a","aaa"); map.put("b","bbb"); map.put("c","ccc"); String json=JSON.toJSONString(map); System.out.println(json);//输出{"a":"aaa","b":"bbb","c":"ccc"}
//JSON转换成Map
Map map1 = JSON.parseObject(json);System.out.println(map1.get("a"));for (Object mapData : map.entrySet()) {Map.Entry entry = (Map.Entry)mapData;System.out.println(entry.getKey()+"--->"+entry.getValue());}
map中含有对象Map -> JSON
//Map -> JSONMapmap = new HashMap (); map.put("a",new Bar()); map.put("b",new Bar()); map.put("c",new Bar()); String json = JSON.toJSONString(map,true); System.out.println(json);
//JSON -> Map
Mapmap1 = (Map )JSON.parse(json); for (String key : map1.keySet()) { System.out.println(key+":"+map1.get(key)); }
来自:http://www.cnblogs.com/DreamDrive/p/5778959.html



