user2074140
user2074140

Reputation:

C# - Deserialize JSON object array

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

Upvotes: 0

Views: 122

Answers (2)

user2074140
user2074140

Reputation:

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

http://json2csharp.com/

=)

Upvotes: 2

MIKE
MIKE

Reputation: 1059

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

Upvotes: 0

Related Questions