Java中将Map转换为JSON

一个注意的地方:要选对jar包

 1         Map map = new HashMap();
 2         map.put("success", "true");
 3         map.put("photoList", photoList);
 4         map.put("currentUser", "zhang");
 5         
 6         //net.sf.json.JSONObject 将Map转换为JSON方法
 7         JSONObject json = JSONObject.fromObject(map);
 8 
 9         //org.json.JSONObject 将Map转换为JSON方法
10         JSONObject json =new JSONObject(map);
原文地址:https://www.cnblogs.com/sere/p/4627536.html