3

I will try to parse the string of JSON but there is a problem to parse 'long' character in JSON string.

JSON code is below

{ "valid": 1, "delta": 0, "time": 23755, "date": 200815, "fix": 2, "status": 1, "sats": 12, "lat": 37529922, "long": 126898053, "speed": 874, "heading": 0, "alt": 171300 }

I want to get lat and long value but I can't get value because Long character is keyword

My code is below

using (WebClient wc = new WebClient())
{
    string json = wc.DownloadString(sb.ToString());
    dynamic temp = JsonConvert.DeserializeObject(json);
    Gps = new GpsInfo();
    Gps.latY = temp.lat;
    Gps.lonX = temp.long; //Error long type is keyword
    SettingGpsChart(Gps);
}

How can I parse json value long and lat?

dbc
  • 104,963
  • 20
  • 228
  • 340
HighEndGuy
  • 141
  • 10
  • 2
    Ad: look - company I work for have search engine too https://www.bing.com/search?q=c%23+json+keyword (better than one you use :)). – Alexei Levenkov Aug 20 '15 at 02:57

1 Answers1

3

Use @ symbol:

Gps.lonX = temp.@long; 

And cast to your type:

Gps.lonX = (long)temp.@long; 
Backs
  • 24,430
  • 5
  • 58
  • 85