【发布时间】:2013-04-01 00:32:23
【问题描述】:
1) 我有一个 JSON 文件:
{
"serverURI":"http://localhost:8080/PocketUNI_API/serverURLs",
"newsURI":"http://localhost:8080/gateway/rss/rss.xml",
"modulesURI":"http://localhost:8080/PocketUNI_API/modules"
}
2) 我需要在 Java 客户端上以字符串格式获取 URL。
String json = jsonReceiver.makeHttpRequest(URL_SERVER, "GET", params);
JSONArray uris = new JSONArray(json);
Receiver 工作正常,json 显示接收到的正确字符串,但是当它使用 JSONArray 解析时会抛出错误
org.json.JSONException: Value {"serverURI":"http:\/\/192.168.0.... of type org.json.JSONObject cannot be converted to JSONArray.
问题:如何解析带有 URL 值的 json?
【问题讨论】:
-
您为什么要尝试将 Object 转换为 Array ?
-
使用 jsonArray 对象循环遍历多个 json 对象
-
你在 dosnt 上面发布的代码似乎有一个 jsonobject 数组,而不是它有一个 json 对象,并且将 obejct 转换为数组会给你 jsonexception 尝试提取单个对象
-
不是
JSONArray,而是JSONObject。 JSONObject json = new JSONObject(str)
标签: java json arrays jsonexception