替换字符串字符以将json转换为对象类

时间:2019-01-17 16:28:51

标签: java string replace

我在JSON字符串下面

{"code":"\"xx\"","aCode":"[\"ab1\",\"ab2\"]","date":"\"20150130\"","wNames":"[\"one\",\"two\"]","cDate":"\"20261231\"","aid":"aid=01,aid=011,id=1,ou=group,o=org","rCode":"\"xxx:yyy:zzz\"","bFuncs":"[\"c1\",\"c2\"]","awCodes":"[\"100:200:300\",\"101:201:301\"]","wCodes":"[\"100001\",\"100002\"]","lName":"\"\"admin\":\"manager - A and C\":\"develop\"\"","aid":"\"011\""}

我必须转换为对象类。 为此,我需要替换字符并在下面的结果格式中期望

{"code":"xx","aCode":["ab1","ab2"],"date":"20150130","wNames":["one","two"],"cDate":"20261231","aid":"aid=01,aid=011,id=1,ou=group,o=org","rCode":"xxx:yyy:zzz","bFuncs":["c1","c2"],"awCodes":["100:200:300","101:201:301"],"wCodes":["100001","100002"],"lName":"\"admin\":\"manager - A and C\":\"develop\"","aid":"011"}

我尝试过

jsonString = jsonString.replaceAll("\\\\", "");
jsonString = jsonString.replace("\"\"", "\"");
jsonString = jsonString.replace("\"[", "[").replace("]\"", "]");

结果低于

{"code":"xx","aCode":["ab1","ab2"],"date":"20150130","wNames":["one","two"],"cDate":"20261231","aid":"aid=01,aid=011,id=1,ou=group,o=org","rCode":"xxx:yyy:zzz","bFuncs":["c1","c2"],"awCodes":["100:200:300","101:201:301"],"wCodes":["100001","100002"],"lName":""admin":"manager - A and C":"develop"","aid":"011"}

有人帮我。谢谢

0 个答案:

没有答案