我正在尝试解析来自此链接的 JSON 响应,但出现此异常:
Expected BEGIN_ARRAY but was BEGIN_OBJECT
我创建了这个类来封装 JSON 数据:
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;
}
}
这是我解析 JSON 的代码:
private ArrayList<PlacesTextSearch> arrayListPlaces;
Type listType = new TypeToken<ArrayList<PlacesTextSearch>>(){}.getType();
arrayListPlaces=new Gson().fromJson(response,listType);
在这里您可以看到完整的异常堆栈跟踪: