Android JSONArray 异常

标签 android json exception

我有一个这样的 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/

相关文章:

java - Android 将其打印到左侧?

java - 为什么setOnClickListener()必须在onCreate()内部?

java - 未处理的异常的输出与程序的输出混淆

c# - 我遇到了 stackoverflowexception,我不确定为什么

.net - 是否可以忽略 Visual Studio 中某些行的某些异常?

android - 最小化android中以前 Activity 中的 Activity

android - Android 在后台杀死应用程序后,NavigationUI.setupActionBarWithNavController 会导致应用程序在启动时崩溃

java - jackson 将额外的字段反序列化为 map

c# - 如何在 ASP.NET 应用程序中序列化异常?

javascript - 使用列名获取存储值 - EXTJS 4