I am trying to parse the JSON response from this link and I'm getting this exception:
Expected BEGIN_ARRAY but was BEGIN_OBJECT
I have created this class to encapsulate the JSON data:
public class PlacesTextSearch {
private String icon;
private String name;
private String types;
private String formatted_address;
private double latitude;
private double longitude;
private String id;
public PlacesTextSearch(String icon,String name,String types,String formatted_address,double latitude,double longitude) {
// TODO Auto-generated constructor stub
setIcon(icon);
setName(name);
setTypes(types);
setFormatted_address(formatted_address);
setLatitude(latitude);
setLongitude(longitude);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTypes() {
return types;
}
public void setTypes(String types) {
this.types = types;
}
public String getFormatted_address() {
return formatted_address;
}
public void setFormatted_address(String formatted_address) {
this.formatted_address = formatted_address;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
}
And this is my code to parse the JSON:
private ArrayList<PlacesTextSearch> arrayListPlaces;
Type listType = new TypeToken<ArrayList<PlacesTextSearch>>(){}.getType();
arrayListPlaces=new Gson().fromJson(response,listType);
Here you can see the complete exception stacktrace:
