Answer the question
In order to leave comments, you need to log in
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ why does the error occur?
Please help with Retrofit. Why does it give an error?
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
{
"city": [
{
"city_id": "6",
"country_id": "4",
"region_id": "5",
"name": "Балларат"
},
{
"city_id": "7",
"country_id": "4",
"region_id": "5",
"name": "Бендиго"
},
{
"city_id": "8",
"country_id": "4",
"region_id": "5",
"name": "Варрнамбул"
}
]
}
class Cities {
@SerializedName("city")
private List city;
public List getCity() {
return city;
}
}
class CityValue {
@SerializedName("city_id")
@Expose
private String city_id;
@SerializedName("counter_id")
@Expose
private String counter_id;
@SerializedName("region_id")
@Expose
private String region_id;
@SerializedName("name")
@Expose
private String name;
}
Answer the question
In order to leave comments, you need to log in
Try to explicitly specify private List<CityValue> city;
Although not 100% sure, you can still try an array and not a list.
By the way, the link to JSON is not opening.
Expected BEGIN_ARRAY but was BEGIN_OBJECT
List<T>
, but the object was received List
. private List<CityValue> city;
public List<CityValue> getCity() {
return city;
}
public void setCity(List<CityValue> city) {
this.city = city;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question