我想简单地从 URL 读取一些 JSON 数据,然后将其转换为 POCO 类的集合,但我似乎无法弄清楚我做错了什么。
这是从 URL 获取的 JSON 数据示例:
[
{
"Name":"Together As One Run",
"Location":"Parkville, MO",
"ScheduledAt":"\/Date(1334984400000)\/",
"URL":"http://www.runningintheusa.com/Race/View.aspx?RaceID=36667"
},
{
"Name":"Lean Green Running Machine 5K Run/Walk and 1 Mile Run",
"Location":"Springfield, MO",
"ScheduledAt":"\/Date(1335589200000)\/",
"URL":"http://www.runningintheusa.com/Race/View.aspx?RaceID=53945"
},
{
"Name":"Festival of Miles",
"Location":"St. Louis, MO",
"ScheduledAt":"\/Date(1338440400000)\/",
"URL":"http://www.runningintheusa.com/Race/View.aspx?RaceID=53901"
},
{
"Name":"Miles Against Melanoma",
"Location":"Saint Charles, MO",
"ScheduledAt":"\/Date(1338613200000)\/",
"URL":"http://www.runningintheusa.com/Race/View.aspx?RaceID=53939"
}
]
我可以用 WebClient 得到这些数据就好了。
我正在像这样设置我的 JsonFX 阅读器:
var json = new JsonReader(new DataReaderSettings(new PocoResolverStrategy()));
这是我的 POCO 课程:
public class Race {
public String Name { get; set; }
public String Location { get; set; }
public DateTime ScheduledAt { get; set; }
public String URL { get; set; }
}
我尝试以多种方式反序列化 JSON 数据,但似乎没有任何效果:
//reader is an instance of StreamReader
var content = reader.ReadToEnd();
//nope
//var output = json.Read<Race>(content);
//nope
//var output = json.Read<Race[]>(content);
这必须是一件简单的事情,我只是找不到解决方案。我花了大约30分钟。谷歌搜索无济于事。任何帮助,将不胜感激!