Django JsonResponse解析Android中的错误

时间:2018-04-25 21:35:36

标签: 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,
           "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中解析此对象。

1 个答案:

答案 0 :(得分:0)

我不确定,但JSON阵列是不是这样开始的?:

[ { } ]

" 0"似乎不是必需的。它将自动订购

编辑:如果您的json有效,您也可以在线查询。只是google Json格式化程序。