我有一个这样的 JSON:
{
- 0: {
"title": "Title1",
"content": "test"
},
- 1: {
"title": "Title2",
"content": "test2"
}
}
所以我想在我的应用程序中恢复它,但这一行有一个异常(exception):
JSONArray jArray = new JSONArray(result);
我检查“结果”包含我的 JSON
,确实如此。
当我在 logcat 中看到错误时,我只看到我的 JSON 的值....我有类似的东西:
org.json.JSONException and values of my JSON
有人可以帮助我吗?
最佳答案
{ 意味着如果 json 数据以 { 开头而不是对象
[ 意味着如果json数据以[开头而不是数组
使用
JSONObject jObject = new JSONObject(result);
代替
JSONArray jArray = new JSONArray(result);
一个简单的教程和学习访问
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
关于Android JSONArray 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22477102/