我对JSON相对较新,并且使用API forecast.io
。它返回下面的JSON,我需要解析它。使用Json.Net解析forecast.io气象数据时遇到问题
"daily":{
"summary":"Drizzle on Monday and Tuesday, with temperatures bottoming out at 91°F on Monday.","icon":"rain",
"data":[{
"time":1463770800,"summary":"Clear throughout the day.","icon":"clearday","sunriseTime":1463788956,"sunsetTime":1463839653,"moonPhase":0.48,"precipIntensity":0,"precipIntensityMax":0,"precipProbability":0,"temperatureMin":63.06,"temperatureMinTime":1463785200,"temperatureMax":95.23,"temperatureMaxTime":1463824800,"apparentTemperatureMin":63.06,"apparentTemperatureMinTime":1463785200,"apparentTemperatureMax":90.3,"apparentTemperatureMaxTime":1463824800,"dewPoint":37.34,"humidity":0.25,"windSpeed":3.44,"windBearing":22,"cloudCover":0,"pressure":1002.14,"ozone":283.7}
我提取了“每日”部分成功,但我无法得到“日常”内的“数据”。我需要详细信息,即摘要,时间,图标等,我真的很感谢一些帮助。
这里是我的C#代码:
所有的var test = new System.Net.WebClient().DownloadString("https://api.forecast.io/forecast/f2857958690caafc67d0dfba402c1f57/" + Latitude + "," + Longitude);
var json = JObject.Parse(test);
var daily = json.ToObject<DailyWeatherDTO>();
public class DailyWeatherDTO
{
public DailyWeatherData daily { get; set; }
}
public class DailyWeatherData
{
public daily data { get; set; }
}
public class daily
{
public string time { get; set; }
public String summary { get; set; }
public String icon { get; set; }
public String precipIntensity { get; set; }
public String precipProbability { get; set; }
public string sunriseTime { get; set; }
public string sunsetTime { get; set; }
public string moonPhase { get; set; }
public string precipIntensityMax { get; set; }
public string temperatureMin { get; set; }
public string temperatureMinTime { get; set; }
public string temperatureMax { get; set; }
public string temperatureMaxTime { get; set; }
public string apparentTemperatureMin { get; set; }
public string apparentTemperatureMinTime { get; set; }
public string apparentTemperatureMax { get; set; }
public string apparentTemperatureMaxTime { get; set; }
public string dewPoint { get; set; }
public string humidity { get; set; }
public string windSpeed { get; set; }
public string windBearing { get; set; }
public string cloudCover { get; set; }
public string pressure { get; set; }
public string ozone { get; set; }
}
我建议你搜索Newtonsoft JSON和看的例子,看看你如何使用它。 –
1)您在问题中包含的JSON不完整。它应该至少包括外括号。你可以编辑你的问题,包括完整的JSON? 2)试图解析JSON后,你有什么问题? – dbc