我需要一些帮助来创建将填充 GSON 解析器的类。这是自动完成 Google Places API 的输出:
{
"predictions" : [
{
"reference" : "CjQtAA",
"terms" : [
{
"offset" : 0,
"value" : "Ladimirevci"
},
{
"offset" : 13,
"value" : "Hrvatska"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"reference" : "CjQtAAA",
"terms" : [
{
"offset" : 0,
"value" : "Ladimirevci"
},
{
"offset" : 13,
"value" : "Hrvatska"
}
],
"types" : [ "locality", "political", "geocode" ]
}
],
"status" : "OK"
}
解决方案感谢 MikO
课程是:
public class GPlacesAPIResults {
@SerializedName("predictions")
public List<GPlacesAPILocation> predictions;
@SerializedName("status")
public String status;
}
第二:
public class GPlacesAPILocation implements Serializable {
private static final long serialVersionUID = 4509808527882750586L;
@SerializedName("reference")
private String reference;
@SerializedName("terms")
private List<GPlacesAPIAddress> terms;
@SerializedName("types")
private List<String> types;
}
第三:
public class GPlacesAPIAddress implements Serializable {
private static final long serialVersionUID = -6916297127791361853L;
@SerializedName("value")
public String value;
}
在应用程序中,我这样称呼它
InputStreamReader in = new InputStreamReader(conn.getInputStream()); //results from places api
GPlacesAPIResults lcs = new Gson().fromJson( in , GPlacesAPIResults.class);
谢谢你的努力:-)