如何在这个 JSON ( http://www.pegelonline.wsv.de/webservices/rest-api/v2/stations.json?includeTimeseries=true&includeCurrentMeasurement=true ) 中访问嵌套数组,例如 timeseries.shortname?我试过这样,但它不起作用。
string url = "http://www.pegelonline.wsv.de/webservices/rest-api/v2/stations.json?includeTimeseries=true&includeCurrentMeasurement=true";
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
WebResponse response = await request.GetResponseAsync();
using (Stream stream = response.GetResponseStream())
{
JsonReader reader = new JsonTextReader(new StreamReader(stream));
dynamic info = JArray.Load(reader);
foreach (var item in info)
{
myModel.Add(new ItemModel()
{
uuid = item.uuid,
number = item.number,
city_longname = item.longname,
timeseries = item.timeseries.shortname
});
}
}
3 项有效,但最后一项(时间序列)给出以下错误:无法对空引用执行运行时绑定