0

I am new to JSON (not C#) and am trying to deserialize the following:

var content =
{"message":"","cod":"200","calctime":"","cnt":1,"list":[{"id":80678,"dt":1439083410,"name":"rvb.name","type":5,"coord":{"lat":55.4033,"lon":37.5617},"distance":57.285,"main":{"temp":288.15,"pressure":999.6,"humidity":76},"rang":1}]}

My Code:

 }
public class Location
{
    public string message { get; set; }
    public string cod { get; set; }
    public string calcutime { get; set; }
    public int cnt { get; set; }
    public List<decimal> coord { get; set; }
    public int distance { get; set; }
}

Location loc = JsonConvert.DeserializeObject<Location>(content);

However, when I deserialize it it will not populate the lat and long attributes.

Can someone please advise what I am missing.

Thanks in advance. NOTE: I am using JSON.NET api

2 Answers 2

2

Check your JSON serial/deserial(ization) classes with:

http://json2csharp.com/

=)

Sign up to request clarification or add additional context in comments.

2 Comments

Great job suggesting a tool that doesn't make the OP reinvent the wheel. He'd probably want to rename the classes it generates though, as List<List> is pretty awful :)
Yes. I noticed that and changed it. Without that site you are really reinventing the wheel...
0

Coord is not a decimal list. It would be in brackets. Create an coord class with lat and lon.

3 Comments

So what would be the data type of lat and long?
Decimal is fine. Just dictionary instead of list
Mate - your'e a champion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.