Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android中的Django JsonResponse解析错误_Java_Android_Python_Django_Python 3.x - Fatal编程技术网

Java Android中的Django JsonResponse解析错误

Java Android中的Django JsonResponse解析错误,java,android,python,django,python-3.x,Java,Android,Python,Django,Python 3.x,这是我从服务器得到的JSON响应: { "0": { "pk": 41, "fields": { "heading": "Empty Lecture Slot", "notification": "There is a free lecture available right now for TE B on 2018-05-02 8:00-9:00", "date": "2018-04-25", "priority": 1

这是我从服务器得到的JSON响应:

{
   "0": {
   "pk": 41,
   "fields": {
       "heading": "Empty Lecture Slot",
       "notification": "There is a free lecture available right now for TE B on 2018-05-02 8:00-9:00",
       "date": "2018-04-25",
       "priority": 1,
           "has_read": false,
           "action": "/dashboard/set_substitute/91959"
       },
       "model": "Dashboard.specificnotification"
   }
}
以下是用于解析此JSON对象的Java代码:

JSONObject jsonObject = new JSONObject(response);
这是我在catch块中遇到的错误:

org.json.JSONException: No value for {"0": {"pk": 41, "fields": {"heading": "Empty Lecture Slot", "notification": "There is a free lecture available right now for TE B on 2018-05-02 8:00-9:00", "date": "2018-04-25", "priority": 1, "has_read": false, "action": "/dashboard/set_substitute/91959"}, "model": "Dashboard.specificnotification"}}

如何在Android中解析此对象。

我不确定,但JSON数组不是这样开始的吗?:

[
{
}
]

此外,“0”似乎不是必需的。它将自动订购


编辑:您还可以在线检查json是否有效。只需google Json formatter。

我认为您必须在Java中实现一个与Json对象匹配的POJO类。在发布问题之前,我检查了它。它是一个有效的JSON。