简体   繁体   中英

Get Latitude and Longitude from Google GeoCoder Json? [C#]

I get the Json from google. it has many details on many things but I just want the longitude and latitude. I have been successfully deserialized json using:

        JavaScriptSerializer jSerialize = new JavaScriptSerializer();
        //var businessObject = jSerialize.Deserialize<string>(configuration);
        Hashtable businessObject = jSerialize.Deserialize<Hashtable>(configuration);

        var o = businessObject["results"];

So, my o object has all that stuff, anyway, I just need the longitude and latitude.. what is the best way to do it?

I cant seem to get the right definition to cast o into strictly typed class (error: cant cast to type)

Skip the Hashtable and deserialize into an instance of your type:

public class Coordinate
{
    public double Longitude { get; set; }

    public double Latitude { get; set; }
}

...

JavaScriptSerializer jSerialize = new JavaScriptSerializer();
var coordinate = jSerialize.Deserialize<Coordinate>(configuration);

I am unfamiliar with the JSON response, so you may need to modify your object model accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM