[英]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.