I an trying to Parse the json results of google places api. I called it using http method and I got the json results back in string How can I parse it ? I reas the doc and vistited the two blogs on the internet( one uses google api library and one seems to be outdated) and didnt help me
I am using the standard java JSONobject and Gson by google, but i am unable to figure out a good way to parse it (i am calling the search places method) What do you recommend? Thank u
Hi, sorry for forgetting to show the JSON response:
{
"html_attributions" : [
"Listings by \u003ca href=\"http://www.yellowpages.ca/\"\u003eYellowPages.ca\u003c/a\u003e"
],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 45.39318670,
"lng" : -75.68352930
},
"viewport" : {
"northeast" : {
"lat" : 45.40102170,
"lng" : -75.66752190
},
"southwest" : {
"lat" : 45.38535060,
"lng" : -75.69953670
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "6a3f8ef9aae04c8a23c80ab814e8c75a8b685292",
"name" : "Old Ottawa South",
"reference" : "adsadada",
"types" : [ "neighborhood", "political" ],
"vicinity" : "Ottawa"
},
{
"geometry" : {
"location" : {
"lat" : 45.394630,
"lng" : -75.6837250
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/movies-71.png",
"id" : "59519a28667351790456ab80aba982347546b2f6",
"name" : "Mayfair Theatre",
"rating" : 4.10,
"reference" : "dfdsf",
"types" : [ "movie_theater", "establishment" ],
"vicinity" : "1074 Bank Street, Ottawa"
}
]
}
I want to grab the results portion (and lets says the first item of the results only for simplicity)and what i did was the following:
JSONObject jso = new JSONObject(response);
String result = jso.getJSONArray("results").getJSONObject(0).toString();
JsonPlacesResult d = new Gson().fromJson(result, JsonPlacesResult.class);
where JsonPlacesResult is
class JsonPlacesResult{
private JsonPlaces jsonPlaces;
public JsonPlaces getJsonPlaces(){return jsonPlaces;}
}
class JsonHtml{
private String html_attribution;
}
class JsonPlaces{
private Geometry geo;
private String icon;
private String id;
private String name;
private String rating;
private String reference;
private String types;
private String vicinity;
}
class Geometry{
private JsonLocation loc;
}
class JsonLocation{
private String lat;
private String lng;
}
I am ending up with null object in d??? Why is this! what did I do wrong Thanks