当我尝试将 JSON 字符串转换为 JSONObject 时出现以下错误。
java.lang.String 类型位置的值48.466667|9.883333无法转换为 JSONObject
字符串是有效的 JSON,我用http://jsonlint.com/对其进行了测试
示例:{"name":"An der Decke","location":" 48.412583|10.0385 ","type":"Virtual","size":null,"status":"Available","difficulty":1 “评级”:空,“地形”:1}
产生异常的代码如下所示:
jsonObject = new JSONObject(result);
jsonArray = new JSONArray();
Iterator<String> iter = jsonObject.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
JSONObject value = (JSONObject) jsonObject.get(key); <---- Exception
jsonArray.put(value);
} catch (JSONException e) {
// Something went wrong!
}
}
是管子| 符号不是Java JSON中的有效字符?
编辑:
问题是,如果 JSON 字符串不包含"location":"48.412583|10.0385"部分,它可以正常工作......