Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse json value long character [duplicate]

Tags:

json

c#

parsing

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?

like image 868
HighEndGuy Avatar asked Feb 12 '26 10:02

HighEndGuy


1 Answers

Use @ symbol:

Gps.lonX = temp.@long; 

And cast to your type:

Gps.lonX = (long)temp.@long; 
like image 156
Backs Avatar answered Feb 16 '26 01:02

Backs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!