1

I'm using an API that send the data as follows:

{
    "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"
    }
}

As you can see, 10/05/2018 & 11/05/2018 are keys that contains arrays of data as values.

I am using Retrofit to get the data. How could I parse the above response to objects? Thanks in advance.

Romeo Sierra
  • 1,666
  • 1
  • 17
  • 35
Kenny Horna
  • 13,485
  • 4
  • 44
  • 71

1 Answers1

2

Please try with the following modal classes.

public class Data{
   AbcDate data;
   public AbcDate getData() {
    return data;
   }

  public void setData(AbcDate data) {
    this.data = data;
   }
 }

// Another Class

public class AbcDate{
   HashMap<String, DetailModel> detail;

public static class DetailModel {
            int detail_id, reservation_id,field_id,;
}

 }
suprita
  • 211
  • 1
  • 9