How to get JSON array without any key in Retrofit (Android)?

I have JSON arraywithout any object (key) inside which there are such JSON Objects:

[
  {
    "Type": "Meeting",
    "Name": "TestMeeting",
    "StartDate": "2016-03-22T08:00:00",
    "EndDate": "2016-03-24T09:00:00"
  }
]

I tried to make it out, but did not find success. Can someone tell me how to parse this type of answer with Retrofit?

+6
source share
1 answer

You can define Classrepresenting a JSON object

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Meeting{

@SerializedName("Type")
@Expose
private String type;
@SerializedName("Name")
@Expose
private String name;
@SerializedName("StartDate")
@Expose
private String startDate;
@SerializedName("EndDate")
@Expose
private String endDate;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getStartDate() {
return startDate;
}

public void setStartDate(String startDate) {
this.startDate = startDate;
}

public String getEndDate() {
return endDate;
}

public void setEndDate(String endDate) {
this.endDate = endDate;
}

}

after that you define Callback for such modification Call<List<Meeting>> getMeetings();

+11
source

Source: https://habr.com/ru/post/1669586/


All Articles