我使用的API按如下方式发送数据:
{
"data": {
"10/05/2018": [
{
"detail_id": 88,
"reservation_id": 85,
"field_id": 1,
"total": 180,
// some other fields
},
{
"detail_id": 89,
"reservation_id": 85,
"field_id": 1,
"field_id": 1,
"total": 180,
// some other fields
}
],
"11/05/2018": [
{
"detail_id": 90,
"reservation_id": 86,
"field_id": 1,
"total": 180,
// some other fields
},
{
"detail_id": 91,
"reservation_id": 86,
"field_id": 1,
"total": 180,
// some other fields
}
]
},
"links": {
"first": "http://159.65.35.171/api/v1/reservations?date=08/05/2018",
"prev": "http://159.65.35.171/api/v1/reservations?date=01/05/2018",
"next": "http://159.65.35.171/api/v1/reservations?date=15/05/2018"
},
"meta": {
"path": "http://159.65.35.171/api/v1/reservations"
}
}
如您所见,10/05/2018
& 11/05/2018
是keys
,其中包含数据数组作为值。
我正在使用Retrofit来获取数据。我怎么能解析上面对对象的响应?提前谢谢。
答案 0 :(得分:1)
请尝试使用以下模态类。
public class Data{
AbcDate data;
public AbcDate getData() {
return data;
}
public void setData(AbcDate data) {
this.data = data;
}
}
//另一个班级
public class AbcDate{
HashMap<String, DetailModel> detail;
public static class DetailModel {
int detail_id, reservation_id,field_id,;
}
}