我坚持我的小问题。
我使用API从服务器获取有关天气的数据。 我对Json的反应很好。
Json:
{"coord":{"lon":-0.13,"lat":51.51},"sys":{"type":3,"id":60992,"message":0.0067,"country":"GB","sunrise":1420358723,"sunset":1420387545},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"cmc stations","main":{"temp":275.05,"humidity":95,"pressure":1035.7,"temp_min":275.05,"temp_max":275.05},"wind":{"speed":2.82,"deg":178.5},"clouds":{"all":64},"dt":1420400811,"id":2634341,"name":"City of Westminster","cod":200}
我可以从以下行获取json数据:
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}]
我的代码:
var json = JObject.Parse(rawJson);
var result = json["weather"];
var data = new List<TheWeather>();
for (int i = 0; i < result.Count(); i++)
{
var desc = (string)result[i]["description"];
data.Add(new TheWeather(desc));
}
return data;
但现在我想要检索&#34;名称&#34;从这一行中的属性我把我放在了实际的Json对象的末尾。 这条线没有任何我刚刚检索到的属性。 该行位于json起始端括号之间。 缩小的json对象示例:
{"coord":{"lon":-0.13,"lat":51.51},"sys":{"type":3,"id":60992,"message":0.0067,"country":"GB","sunrise":1420358723,"sunset":1420387545} "name":"City of Westminster","cod":200}
我如何获得&#34;名称&#34;从这个json对象? 请帮忙!