[英]JSONObject[str] is not a JSONObject while parsing JSON
I am trying to deserialize (parse) this JSON: {"test": "TEST2"}
我正在尝试反序列化(解析)此JSON:
{"test": "TEST2"}
I am new to Java, so I've searched a lot on Google and I finally found the answer here: https://stackoverflow.com/a/18998203/8524395 我是Java的新手,所以在Google上进行了很多搜索,终于在这里找到了答案: https : //stackoverflow.com/a/18998203/8524395
So, I am trying to deserialize my JSON like that: 所以,我试图像这样反序列化我的JSON:
JSONObject obj = new JSONObject("{\"test\": \"TEST2\"}");
String testValue = obj.getJSONObject("test").toString();
But I am getting the error: JSONObject obj = new JSONObject("{\\"test\\": \\"TEST2\\"}"); String pageName = obj.getJSONObject("test").toString();
但是我得到了错误:
JSONObject obj = new JSONObject("{\\"test\\": \\"TEST2\\"}"); String pageName = obj.getJSONObject("test").toString();
JSONObject obj = new JSONObject("{\\"test\\": \\"TEST2\\"}"); String pageName = obj.getJSONObject("test").toString();
Any help would be appreciated. 任何帮助,将不胜感激。
Thanks! 谢谢!
You should get a string not another object: 您应该得到一个字符串而不是另一个对象:
String testValue = obj.getString("test");
In other word, test
is a key that maps to a string of value TEST2
. 换句话说,
test
是映射到值TEST2
的字符串的键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.