问题初始化的JSONObject [英] Issue initializing a JSONObject
本文介绍了问题初始化的JSONObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想初始化的JSONObject与下面的字符串,从Web服务接收到的:
I'm trying to initialize a JSONObject with the following string, received from a web service:
"{
"campaignid": "8",
"campaignname": "Pilotarienak 2011",
"campaignlink": "http:\\/\\/www.xxx.com\\/fr\\/cote-basque\\/agenda\\/2011-05-20\\/FMAAQU064FS016DV-pilotarienak-d-anglet?fromapp",
"splash": "http:\\/\\/www.xxx.com\\/ads\\/customers\\/pilotarienak\\/320x480.jpg",
"banner": "http:\\/\\/www.xxx.com\\/ads\\/customers\\/pilotarienak\\/320x160.jpg"
}"
这似乎是有效的JSON(它验证在jsonlint.com),但与初始化一个JSONObject的,当我得到:
It seems to be valid json (it validates in jsonlint.com), but when initializing a JSONObject with that I get:
org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
任何人都可以帮忙吗?
Anybody can help?
感谢
推荐答案
好像你正试图从额外引号中的字符串初始化它。您需要删除包装报价(我没有使用你的字符串,但举个例子,以使其更清晰):
Seems like you are trying to instantiate it from a String with extra quotes. You need to remove the wrapping quotes(I'm not using your string, but giving an example to make it clearer):
这是确定:
String jStr= "{\"param1\":\"hello\"}";
JSONObject jObj = new JSONOBject(jStr);
这是不是:
String jStr= "\"{\"param1\":\"hello\"}\"";
// note this ^^ and this ^^
JSONObject jObj = new JSONOBject(jStr);
这篇关于问题初始化的JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文