这是我从服务器获得的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中解析此对象。
答案 0 :(得分:0)
我不确定,但JSON阵列是不是这样开始的?:
[
{
}
]
" 0"似乎不是必需的。它将自动订购
编辑:如果您的json有效,您也可以在线查询。只是google Json格式化程序。