【发布时间】:2012-06-13 17:49:27
【问题描述】:
我有以下问题: 我在尝试在 Android 中解析的服务器上有一个 JSON 文件。但我收到以下错误消息:
06-13 19:24:39.025:E/JSON Parser(17169):解析数据时出错 org.json.JSONException: java.lang.String 类型的值 不能 转换为 JSONObject
这是我的 JSON 文件:
{
"settings":[
{
"rss":"true",
"rss_feed":"http://test.com/rss.rss"
}
],
"map_locations":[
{
"title":"Büro Toronto",
"address":"123 Younge Street Toronto"
},
{
"title":"Büro New York",
"address":"Time Square New York"
}
]
}
这是我的代码:
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(SETTINGS_URL);
try {
JSONObject c = json.getJSONArray("settings").getJSONObject(0);
rss = c.getBoolean("rss");
JSONArray jMap = json.getJSONArray("map_locations");
for (int i = 0; i < jMap.length(); i++) {
JSONObject c2 = jMap.getJSONObject(i);
String map_title = c2.getString("title");
String map_address = c2.getString("address");
mapListTitle.add(map_title);
mapListAddress.add(map_address);
}
URL_TO_RSSFEED = c.getString("rss_feed");
} catch (JSONException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
提前感谢您的帮助!
奇怪的是,我没有改变任何东西(据我所知)并且它之前确实有效。 如果您需要更多信息,请告诉我!
【问题讨论】:
-
你到底是什么意思?像 UTF-8 问题之类的?我也试过用“ue”而不是“ü”,但这并没有改变任何东西......
-
@user754730 : 您可以从这里检查 api 返回的 json 是否有效jsonviewer.stack.hu
-
JSON 在网站上看起来确实不错...
标签: android json parsing jsonexception