Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this string

HTML
<input type="hidden" name="myinput" id="myinput" value='{"lat":11.111111,"lon":22.222222}'>


I need to get lat and long values. How can I get them? Thanks.

What I have tried:

I don't know how to parse this string. Thanks.
Posted
Updated 18-Nov-16 4:53am
Comments
[no name] 18-Nov-16 10:01am    
Deserialize the JSON with a JSON deserializer.

1 solution

in Javascript
JavaScript
var value = document.getElementById('myinput').value;
        var obj = JSON.parse(value);
        var lat = obj.lat;
        var long = obj.lon;


c#
C#
public class Geo
       {
           public string lat { get; set; }
           public string lon { get; set; }
       }


C#
JavaScriptSerializer js = new JavaScriptSerializer();
         string json = myinput.Value;
         var data = js.Deserialize<Geo>(json);
         var lat = data.lat;
         var lon = data.lon

You will have to add runat="server attribute to the input element to make it as a server control, so that it can be accessed in code behind.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900