java中字符串怎么转json?

如题所述

第1个回答  2022-11-16
string类型如果要转换成json的话,就需要写成这样的形式,如下:\x0d\x0aString jsonStr ="{'id':'11','parentId':'root','refObj':{'existType':'exist','deptType':'emp','treeNodeType':'dept'}}";\x0d\x0a JSONObject jsonObj = new JSONObject(jsonStr);\x0d\x0a JSONObject refObj = new JSONObject(jsonObj.getString("refObj"));\x0d\x0a String existType = refObj.getString("existType");\x0d\x0a System.out.println(existType);\x0d\x0ajar使用的是org.json.jar

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网