反序列化对象C#

时间:2016-04-03 02:23:31

标签: c# arrays json json.net

我有以下json:

{
    "coord":{"lon":-88.92,"lat":44.46},
    "weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],
    "main":{"temp":271.72,"pressure":1009,"humidity":73,"temp_min":269.15,"temp_max":273.15},
    "name":"XXXXX",
}

我正在尝试使用这个类在C#中反序列化:

public class weatherClass
{

    [JsonProperty("name")]
    public string Name { get; set;}

    [JsonProperty("main")]
    public Info Main { get; set;}

    [JsonProperty("weather")]
    public List<InfoWeather> Weather { get; set; }
}

public class Info{
    public string temp { get; set;}
    public string pressure { get; set;}
}

public class InfoWeather {
    public string description { get; set;}
    public string main { get; set;}
}

我可以从Info Class获取临时压力。但是我遇到了InfoWeather的问题。它没有返回任何内容:

weatherResult.Text = string.Format("The city is: {0} and the description is: {1}", weatherlass.Name, weatherlass.Weather);

如果我使用weatherlass.Weather.description

enter image description here

1 个答案:

答案 0 :(得分:1)

this.props.{propName}