直接去maven仓库下载:连接地址
示例:



将不同类型的对象存入Map,再转换为Json
前端(Ajax)得到的数据结构为:{...}
// 将数据存入map
Map map = new HashMap();
map.put("list",list);
map.put("int",int);
map.put("object",Object);
// 将map转换为Json {}
JSONObject mapJson = JSONObject.fromObject(map);
前端(Ajax)得到的数据结构为:[...]
JSONArray arrayJson = JSONArray.fromObject(list);
原文:https://www.cnblogs.com/langkyeSir/p/13194070.html