java中字符串怎么转json?

如题所述

string类型如果要转换成json的话,就需要写成这样的形式,如下:
String jsonStr ="{'id':'11','parentId':'root','refObj':{'existType':'exist','deptType':'emp','treeNodeType':'dept'}}";
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject refObj = new JSONObject(jsonObj.getString("refObj"));
String existType = refObj.getString("existType");
System.out.println(existType);
jar使用的是org.json.jar
温馨提示:答案为网友推荐,仅供参考