寻找伦敦目前的天气和天气预报 woeid 44418 https://query.yahooapis.com/v1/public/yql? q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20woeid%20%3D044418)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
如何预测? 以下是今天的天气代码。
origin
答案 0 :(得分:0)
只能说Yahoo Weather JSON格式。结果将在query.results.channel.item.forecast
。查看以下示例,该示例使用Newtonsoft.Json
进行JSON解析:
dynamic jsonData = JObject.Parse(responseFromServer);
if (jsonData["query"].count == 0)
{
throw new Exception("Failed to obtain forecast from the server.");
}
var convertFromFtoC = jsonData["query"].results.channel.units.temperature == "F";
foreach (var v in jsonData["query"].results.channel.item.forecast)
{
var date = (DateTime)v.date;
var tempLo = (int)v.low;
var tempHi = (int)v.high;
if (convertFromFtoC)
{
tempLo = TemperatureConverter.FahrenheitToCelcius(tempLo);
tempHi = TemperatureConverter.FahrenheitToCelcius(tempHi);
}
dailyForecst.Add(new ForecastDataForTheDay { Date = date, TempLo = tempLo, TempHi = tempHi });
}