I started using the Google Places api by calling the following url
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&sensor=true&key=AddYourOwnKeyHere
I found a post here on stackoverflow that showed the the basic structure of classes I need to to parse the json with gson. Here is what I have so far.
public class GoogleMapper
{
@SerializedName("debug_info")
private List<String> debug_info;
@SerializedName("html_attributions")
private List<String> html_attributions;
@SerializedName("next_page_token")
private String next_page_token;
@SerializedName("results")
private List<Results> results;
@SerializedName("status")
private String status;
}
public class Results
{
@SerializedName("formatted_address")
private String formatted_address;
@SerializedName("icon")
private String icon;
@SerializedName("id")
private String id;
@SerializedName("name")
private String name;
@SerializedName("rating")
private Double rating;
@SerializedName("reference")
private String reference;
@SerializedName("types")
private List<String> types;
}
And here is the main method
public static void main(String[] args)
{
Places p = new Places();
try
{
String page = p.getPage();
Gson gson = new GsonBuilder().serializeNulls().create();
JsonParser parser = new JsonParser();
JsonObject o = (JsonObject)parser.parse(page);
String json = gson.toJson(o);
GoogleMapper mapper = gson.fromJson(json, GoogleMapper.class);
}
catch (Exception e)
{
e.printStackTrace();
}
}
When I run the program I get no errors. But how do I get the parsed data printed?