У меня есть JSON с этой структурой:
{
"response": {
"2018-11-19": [
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:30",
"iso": "2018-11-19T10:30:00",
"day": "19"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "08:00",
"iso": "2018-11-19T08:00:00",
"day": "19"
},
"id": "20181119080000001018"
},
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:30",
"iso": "2018-11-19T10:30:00",
"day": "19"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "09:30",
"iso": "2018-11-19T09:30:00",
"day": "19"
},
"id": "20181119093000001018"
},
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:30",
"iso": "2018-11-19T10:30:00",
"day": "19"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:00",
"iso": "2018-11-19T10:00:00",
"day": "19"
},
"id": "20181119100000001018"
},
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:30",
"iso": "2018-11-19T10:30:00",
"day": "19"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:30",
"iso": "2018-11-19T10:30:00",
"day": "19"
},
"id": "20181119103000001018"
}
],
"2018-11-16": [
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "11:15",
"iso": "2018-11-16T11:15:00",
"day": "16"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "10:00",
"iso": "2018-11-16T10:00:00",
"day": "16"
},
"id": "20181116100000001018"
},
{
"date_end": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "11:15",
"iso": "2018-11-16T11:15:00",
"day": "16"
},
"date_start": {
"year": "2018",
"day_verbose": "Sun",
"month": "11",
"month_verbose": "Nov",
"time": "11:15",
"iso": "2018-11-16T11:15:00",
"day": "16"
},
"id": "20181116111500001018"
}
]
},
"success": true,
"error": {}
}
Основная сложность в том, что здесь может быть много объектов типа «2018-11-19». И их имена заранее неизвестны.
Я могу разобрать поле «success» и объект «Error», но у меня возникли проблемы с объектом «Response». Я получаю «ОК» HTTP-код с нулевым объектом ответа. Я думаю, что с отображением что-то не так.
Вот мои классы для картографии:
public class AppointmentListApiResponse extends ApiResponse {
@SerializedName("response")
@Expose
private Response response;
@SerializedName("success")
@Expose
private Boolean success;
@SerializedName("error")
@Expose
private Error error;
// getters and setters
public class Response {
// I've tried these versions
//private Map<String, AppointmentInfo> appoints;
//private Map<String, List<AppointmentInfo>> appoints;
//private List<List<AppointmentInfo>> appoints;
// but they don't work for me
// getters and setters
}
А это класс AppointmentInfo:
public class AppointmentInfo {
@SerializedName("date_start")
@Expose
private Date dateStart;
@SerializedName("date_end")
@Expose
private Date dateEnd;
@SerializedName("id")
@Expose
private String id;
// getters and setters
public class Date {
@SerializedName("day")
@Expose
private String day;
@SerializedName("day_verbose")
@Expose
private String dayVerbose;
@SerializedName("iso")
@Expose
private String dateTime;
@SerializedName("month")
@Expose
private String month;
@SerializedName("month_verbose")
@Expose
private String monthVerbose;
@SerializedName("time")
@Expose
private String time;
@SerializedName("year")
@Expose
private String year;
// getters and setters
}
}