String 转 json
JSONObject jasonObject = JSONObject.fromObject(str);
String 转 Map
JSONObject jasonObject = JSONObject.fromObject(str);
Map map = (Map)jasonObject;
注:以上之所以能强转为Map类型,是因为JSONObject实现了Map接口
Map 转 json
Map<String,String> map = new HashMap<>();
map.put("aa","11");
map.put("bb","22");
map.put("cc","33");
JSONObject jb = JSONObject.fromObject(map);
String json = jb.toString();