[英]Retrofit Response Json
我正在为 Android 开发应用程序,当我提交GET
时,REST Server 返回以下 JSON 答案:
{
"result": "ok",
"code": 1000,
"code_desc": "Command Done Successfully",
"method": "get",
"call_id": null,
"timestamp": 1539100644,
"weight": {
"1": {
"id": 1,
"customer_id": 1,
"date": "2018-10-04 12:02:00",
"value": 100,
"observations": ""
},
"2": {
"id": 2,
"customer_id": 1,
"date": "2018-10-04 12:02:00",
"value": 100,
"observations": ""
}
},
"order": "date",
"sorder": "ASC",
"total": 2
}
JSON 是有效的,但是当我尝试读取内容时,它返回null
。 我认为是因为物体重量的形成不好。
来自服务器的 JSON 是否应该更改? 类似于:
{
"result": "ok",
"code": 1000,
"code_desc": "Command Done Successfully",
"method": "get",
"call_id": null,
"timestamp": 1539100644,
"weight": [{
"id": 1,
"customer_id": 1,
"date": "2018-10-04 12:02:00",
"value": 100,
"observations": ""
},
{
"id": 2,
"customer_id": 1,
"date": "2018-10-04 12:02:00",
"value": 100,
"observations": ""
}
],
"order": "date",
"sorder": "ASC",
"total": 2
}
很可能您正在尝试将响应读入某些List<Object>
而服务器响应看起来像Map<String, Object>
。 考虑到它,尝试更改您的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.