Home > C#.NET > Deserialize google places json api using JSON.NET C#

Deserialize google places json api using JSON.NET C#

https://maps.googleapis.com/maps/api/place/search/json?location=8.487495,76.948623&radius=50000&sensor=false&key=Your_key&types=bank

The above link will list all banks near trivandrum in json format (around 50km).

The format is

{
“debug_info” : [],
“html_attributions” : [
“Listings by \u003ca href=\”http://www.indiacom.com/\”\u003eIndiacom Yellow Pages\u003c/a\u003e”
],
“next_page_token” : “ClRNAAAAiET0Jb-GWSPRrClKlXoDqUzA70eEBaa2oKXpN0uBnZ0rVeGkmia0x8IT78UKkXnJZ9IKDhXRsydMw-20Qu1vFf0U5WHKd_Vyt6OwA6etDC8SENOghFC6xxe63lx7VL7i5O4aFGrN8gtl_GaPmBQlqcQGYUdnZoao”,
“results” : [
{
“geometry” : {
“location” : {
“lat” : 8.5280190,
“lng” : 76.9387870
}
},
“icon” : “http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png”,
“id” : “03d8927f980ecbe599326209ee5018ebbf1d54e6”,
“name” : “Syndicate Bank”,
“reference” : “CnRtAAAA_LbcYBdQ5KDQqNoHxaT2YLBfU5H6cnoi5MgcaFLHcGQQH6EAMKeNzi8KPtNjoTE1d1nBftN0a100yFJ5V103RWO6zZgfsJCb1D33A8DIyr6DyBm4CXOhjECWv5RPf3oriP2WbmQ5U5o8JzloTFApaBIQRZlVXmu5Npmx9SvoQ4a7kBoUzlHi7IgB3JtUAXo8WWCPhi_VQRI”,
“types” : [ “bank”, “finance”, “establishment” ],
“vicinity” : “Kesavadasapuram, Thiruvananthapuram”
}

],
“status” : “OK”
}

You can deserialize in to objects using JSON.NET

The class format should be

public class GooglePlacesResponse
{
public string status { get; set; }
public results[] results { get; set; }
}

public class results
{
public geometry geometry { get; set; }
public string name { get; set; }
public string reference { get; set; }
public string vicinity { get; set; }
}

public class geometry
{
public location location { get; set; }
}

public class location
{
public string lat { get; set; }
public string lng { get; set; }
}

Download json string and Deserialize using JsonConvert class in JSON.NET

WebClient wc = new WebClient();
string jsonStr = wc.DownloadString("https://maps.googleapis.com/maps/api/place/search/json?location=" + currentLoc + "&radius=50000&sensor=false&key=Your_Key&types=" + value);
GooglePlacesResponse gpr = (GooglePlacesResponse)JsonConvert.DeserializeObject<GooglePlacesResponse>(jsonStr);

Image
Happy deserializing:)

Advertisements
  1. Muhammad Awais
    January 9, 2015 at 4:25 pm

    Great,,, well i am new at google APIs, i am doing my FYP in which i need to command self-driven robot,,, for this i am using Google Directions API, but i am unable to get data from JSON response, please help me about that 😦

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: