简体   繁体   中英

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

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

http://json2csharp.com/

=)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM