tags:

views:

44

answers:

1

Hi, 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)

+1  A: 

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.

HTH,
Kent

Kent Boogaart
thanks, i was trying from morning, dint work, tried it again, now its working! prolly i did not include double, was trying with string!
iamserious
thanks!!!!!!!!!!
iamserious