San*_*til 6 android jsonexception
我试图从资产文件夹中读取JSON文件.但我得到以下异常
org.json.JSONException: Expected literal value at character 550
我搜索了很多东西,但没有找到任何相关的东西.这是我的JSON文件.
我发现550上的JSON对象是"names": ["Santosh","Sandip","Arvind"],.我试图解决它,但不知道我的代码中发生了什么.
这是我的代码.
我也调试我的代码,但是当控制继续时,JSONObject jsonObject = new JSONObject(text);它抛出异常并进入第一个catch块.
请给我任何参考或提示来解决这个问题.
任何帮助赞赏.
the*_*osh 14
你的JSON无效.
你的JSON应该是这样的
{
"resultCount": 3,
"SearchedTerm": "Wada Pav",
"results": [
{
"locationname": "Mahableshwar Hotel",
"locationid": "12345",
"locationaddress": "baner, Pune",
"dishrating": "4",
"dishname": "Wada Pav",
"dishid": "234",
"dishcategory": "Snacks",
"dishnotes": "Spicy Wada Pav",
"dishpreviewurl": "http://xxx.yyy.zzz/mahableshwar/1.jpg",
"dishtotalvotes": "9999",
"friendslistvoted": {
"friendscount": "3",
"names": [
"Santosh",
"Sandip",
"Arvind"
]
},
"dishimageurl": "http://xxx.yyy.zzz/mahableshwar/2.jpg",
"mylastrating": "4"
}
]
}
Run Code Online (Sandbox Code Playgroud)
在使用它之前尝试使用JSON验证器(如JSLint).
我正在使用以下来获得标准的JSON格式.这个更好.
public static String convertStandardJSONString(String data_json) {
data_json = data_json.replaceAll("\\\\r\\\\n", "");
data_json = data_json.replace("\"{", "{");
data_json = data_json.replace("}\",", "},");
data_json = data_json.replace("}\"", "}");
return data_json;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22907 次 |
| 最近记录: |