Search code examples
javascriptasp.netgoogle-maps-api-3javascriptserializer

Retrieving Serialized Values


I am using JavaScript serializer to send value to JavaScript:

JavaScriptSerializer oSerializer = new JavaScriptSerializer();

        var Result = (from c in dt.AsEnumerable()
                      select new
                      {
                          Latitude = c.Field<Decimal>("Latitude"),
                          Longitude = c.Field<Decimal>("Longitude")
                      }).ToList();

        hdnControl.Value = oSerializer.Serialize(Result);

This results in this kind of value:

   [
    {"Latitude":19.2094000000,"Longitude":73.0939000000},
    {"Latitude":19.2244070000,"Longitude":73.1545760000},
    {"Latitude":32.5838493257,"Longitude":132.3632812500},
    {"Latitude":59.3331894266,"Longitude":8.6572265625}
   ]

How can I retrieve these values in a JavaScript function? Are there any inbuilt method to access it or do I need to use the .split() function to get the values?

Any help will be appreciated.


Solution

  • This is javascript json array. You can use forEach to retrieve the value using the keys

    a.forEach(function(item){
    document.write('<pre> Latitute is '+item.Latitude+'</pre>')
    })
    

    A complete list of of array methods is available HERE which can be used as required

    JSFIDDLE