解析如下JSON:
{
result: [
{
EventType: {
EventTypeDesc: "horse-racing",
events: {
Local: {
Events: {
530857: {
Venue: "Northam",
StateCode: "WA",
CountryCode: "AUS"
},
530858: {
Venue: "Caulfield",
StateCode: "VIC",
CountryCode: "AUS"
}
}
}
}
}
}
]
}
字符串
我可以通过以下代码访问元素:
responseDeserializeObject.result[0].EventType.events.Local.Events[“530857”].Venue
但是,以下C#代码不起作用:
dynamic responseDeserializeObject = HttpGetResponse(endPoint);
foreach (var event in responseDeserializeObject.result[0].EventType.events.Local.Events)
{
Console.WriteLine(event.Venue);
Console.WriteLine(event.StateCode);
Console.WriteLine(event.CountryCode);
}
型
任何帮助都将受到高度赞赏。
2条答案
按热度按时间eivnm1vs1#
我认为你的
Events
是一个字典,所以你需要在foreach
循环中获取KeyValuePair
并访问它的Value
属性。并且还更改了作用域变量名event
,它将无法编译,event
是保留字。字符串
bihw5rsg2#
你完成这个剧本了吗?