【问题标题】:Django JsonResponse parsing error in AndroidAndroid中的Django JsonResponse解析错误
【发布时间】:2018-10-06 11:40:27
【问题描述】:

这是我从服务器得到的 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 中解析这个对象。

【问题讨论】:

  • 我认为你必须在Java中实现一个与JSON对象匹配的POJO类

标签: java android python django python-3.x


【解决方案1】:

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

[ { } ]

“0”似乎也不是必需的。它会自动排序

编辑:您也可以在线检查您的 json 是否有效。只需谷歌 Json 格式化程序。

【讨论】:

  • 我在发布问题之前检查了它。这是一个有效的 JSON。
猜你喜欢
  • 1970-01-01
  • 2013-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 2016-08-30
相关资源
最近更新 更多