C# 如何使用列表使用JSON响应

C# 如何使用列表使用JSON响应,c#,json,C#,Json,我有课 public class RootObject { public List<Weather> weather {get;set;} } public class Weather { public int id {get;set;} public string description {get;set} } 或 我如何读取数据。请帮助您获得天气列表 你需要像这样做 foreach(Weather weather in list) { Console.WriteLine(wea

我有课

public class RootObject
{
public List<Weather> weather {get;set;}
}
public class Weather
{
public int id {get;set;}
public string description {get;set}
}


我如何读取数据。请帮助

您获得天气列表

你需要像这样做

foreach(Weather weather in list)
{
Console.WriteLine(weather.description)
}

不能从这样的列表中访问一个元素。您必须问问自己要访问哪个元素,例如
list[5].id
,或
list.First().id
。JSON字符串是什么样子的?现在我得到了id和description的值。但现在的问题是,当我尝试给字符串赋值时,它会给我一个异常,比如“对象引用未设置为对象的实例”,我会检查软件“postman”中的JSON响应,该响应不为null。weather_lbl.Text=nObj.Main.temp.ToString()@Luc字符串类似于(“);
Console.Writeline(list.id);
Console.Writeline(list.description);
foreach(Weather weather in list)
{
Console.WriteLine(weather.description)
}