@Qamrand

Expected BEGIN_ARRAY but was BEGIN_OBJECT при полученния данных с сервера через Retrofit?

Ошибка: W/System.err: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

Ответ JSON:

{
                 "type":"ATM",
                 "cityRU":"Днепропетровск",
                 "cityUA":"Днiпропетровськ",
                 "cityEN":"Dnipropetrovsk",
                 "fullAddressRu":"Украина,область Днепропетровская,город Днепропетровск,улица Малиновского,дом 34б",
                 "fullAddressUa":"Украiна,область Днiпропетровська,мiсто Днiпропетровськ,вулиця Малиновського,будинок 34б",
                 "fullAddressEn":"Ukraine,area Dnipropetrovska,city Dnipropetrovsk,building 34b",
                 "placeRu":"Магазин \"Мясо\"",
                 "placeUa":"Магазин \"Мясо\"",
                 "latitude":"48.480873",
                 "longitude":"35.071341",
                 "tw":{
                    "mon":"09:00 - 20:00",
                    "tue":"09:00 - 20:00",
                    "wed":"09:00 - 20:00",
                    "thu":"09:00 - 20:00",
                    "fri":"09:00 - 20:00",
                    "sat":"09:00 - 20:00",
                    "sun":"09:00 - 20:00",
                    "hol":"09:00 - 20:00"
                 }
              }


POJO класс сгенерирован с помощью сервиса www.jsonschema2pojo.org

После генерации POJO получилось следующее:
public class AtmData implements Serializable {

    @SerializedName("type")
    @Expose
    private String type;
    @SerializedName("cityRU")
    @Expose
    private String cityRU;
    @SerializedName("cityUA")
    @Expose
    private String cityUA;
    @SerializedName("cityEN")
    @Expose
    private String cityEN;
    @SerializedName("fullAddressRu")
    @Expose
    private String fullAddressRu;
    @SerializedName("fullAddressUa")
    @Expose
    private String fullAddressUa;
    @SerializedName("fullAddressEn")
    @Expose
    private String fullAddressEn;
    @SerializedName("placeRu")
    @Expose
    private String placeRu;
    @SerializedName("placeUa")
    @Expose
    private String placeUa;
    @SerializedName("latitude")
    @Expose
    private String latitude;
    @SerializedName("longitude")
    @Expose
    private String longitude;
    @SerializedName("tw")
    @Expose
    private Tw tw;

    private final static long serialVersionUID = 487824075428735316L;

    public String getType() {
        return type;
    }

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

    public AtmData withType(String type) {
        this.type = type;
        return this;
    }

    public String getCityRU() {
        return cityRU;
    }

    public void setCityRU(String cityRU) {
        this.cityRU = cityRU;
    }

    public AtmData withCityRU(String cityRU) {
        this.cityRU = cityRU;
        return this;
    }

    public String getCityUA() {
        return cityUA;
    }

    public void setCityUA(String cityUA) {
        this.cityUA = cityUA;
    }

    public AtmData withCityUA(String cityUA) {
        this.cityUA = cityUA;
        return this;
    }

    public String getCityEN() {
        return cityEN;
    }

    public void setCityEN(String cityEN) {
        this.cityEN = cityEN;
    }

    public AtmData withCityEN(String cityEN) {
        this.cityEN = cityEN;
        return this;
    }

    public String getFullAddressRu() {
        return fullAddressRu;
    }

    public void setFullAddressRu(String fullAddressRu) {
        this.fullAddressRu = fullAddressRu;
    }

    public AtmData withFullAddressRu(String fullAddressRu) {
        this.fullAddressRu = fullAddressRu;
        return this;
    }

    public String getFullAddressUa() {
        return fullAddressUa;
    }

    public void setFullAddressUa(String fullAddressUa) {
        this.fullAddressUa = fullAddressUa;
    }

    public AtmData withFullAddressUa(String fullAddressUa) {
        this.fullAddressUa = fullAddressUa;
        return this;
    }

    public String getFullAddressEn() {
        return fullAddressEn;
    }

    public void setFullAddressEn(String fullAddressEn) {
        this.fullAddressEn = fullAddressEn;
    }

    public AtmData withFullAddressEn(String fullAddressEn) {
        this.fullAddressEn = fullAddressEn;
        return this;
    }

    public String getPlaceRu() {
        return placeRu;
    }

    public void setPlaceRu(String placeRu) {
        this.placeRu = placeRu;
    }

    public AtmData withPlaceRu(String placeRu) {
        this.placeRu = placeRu;
        return this;
    }

    public String getPlaceUa() {
        return placeUa;
    }

    public void setPlaceUa(String placeUa) {
        this.placeUa = placeUa;
    }

    public AtmData withPlaceUa(String placeUa) {
        this.placeUa = placeUa;
        return this;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public AtmData withLatitude(String latitude) {
        this.latitude = latitude;
        return this;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public AtmData withLongitude(String longitude) {
        this.longitude = longitude;
        return this;
    }

    public Tw getTw() {
        return tw;
    }

    public void setTw(Tw tw) {
        this.tw = tw;
    }

    public AtmData withTw(Tw tw) {
        this.tw = tw;
        return this;
    }

}


и

public class Tw implements Serializable {

    @SerializedName("mon")
    @Expose
    private String mon;
    @SerializedName("tue")
    @Expose
    private String tue;
    @SerializedName("wed")
    @Expose
    private String wed;
    @SerializedName("thu")
    @Expose
    private String thu;
    @SerializedName("fri")
    @Expose
    private String fri;
    @SerializedName("sat")
    @Expose
    private String sat;
    @SerializedName("sun")
    @Expose
    private String sun;
    @SerializedName("hol")
    @Expose
    private String hol;
    private final static long serialVersionUID = 3057938450733905366L;

    public String getMon() {
        return mon;
    }

    public void setMon(String mon) {
        this.mon = mon;
    }

    public Tw withMon(String mon) {
        this.mon = mon;
        return this;
    }

    public String getTue() {
        return tue;
    }

    public void setTue(String tue) {
        this.tue = tue;
    }

    public Tw withTue(String tue) {
        this.tue = tue;
        return this;
    }

    public String getWed() {
        return wed;
    }

    public void setWed(String wed) {
        this.wed = wed;
    }

    public Tw withWed(String wed) {
        this.wed = wed;
        return this;
    }

    public String getThu() {
        return thu;
    }

    public void setThu(String thu) {
        this.thu = thu;
    }

    public Tw withThu(String thu) {
        this.thu = thu;
        return this;
    }

    public String getFri() {
        return fri;
    }

    public void setFri(String fri) {
        this.fri = fri;
    }

    public Tw withFri(String fri) {
        this.fri = fri;
        return this;
    }

    public String getSat() {
        return sat;
    }

    public void setSat(String sat) {
        this.sat = sat;
    }

    public Tw withSat(String sat) {
        this.sat = sat;
        return this;
    }

    public String getSun() {
        return sun;
    }

    public void setSun(String sun) {
        this.sun = sun;
    }

    public Tw withSun(String sun) {
        this.sun = sun;
        return this;
    }

    public String getHol() {
        return hol;
    }

    public void setHol(String hol) {
        this.hol = hol;
    }

    public Tw withHol(String hol) {
        this.hol = hol;
        return this;
    }
}
  • Вопрос задан
  • 93 просмотра
Решения вопроса 1
@YuryBorodkin
Android dev
скорее всего в в ответе ретрофит сервиса ты указал AtmData[] или List как возвращаемое значение вместо AtmData
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы