【问题标题】:How to cast a JSON that has date as keys in Android [duplicate]如何在Android中转换以日期为键的JSON [重复]
【发布时间】:2018-10-18 00:00:53
【问题描述】:

我正在使用如下发送数据的 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/201811/05/2018keys,其中包含作为值的数据数组。

我正在使用 Retrofit 来获取数据。如何解析上述对对象的响应?提前致谢。

【问题讨论】:

标签: android json parsing retrofit


【解决方案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,;
}

 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2014-12-08
    • 2010-11-17
    • 1970-01-01
    相关资源
    最近更新 更多