嘿,我需要一些帮助循环通过我的字典列表。我似乎无法找到正确的语法。VB.net字典循环
这里是我的代码:
Dim all = New Dictionary(Of String, Object)()
Dim info = New Dictionary(Of String, Object)()
Dim theShows As String = String.Empty
info!Logo = channel.SelectSingleNode(".//img").Attributes("src").Value
info!Channel = .SelectSingleNode("channel.//span[@class='channel']").ChildNodes(1).ChildNodes(0).InnerText
info!Station = .SelectSingleNode("channel.//span[@class='channel']").ChildNodes(1).ChildNodes(2).InnerText
info!Shows = From tag In channel.SelectNodes(".//a[@class='thickbox']")
Select New With {channel.Show = tag.Attributes("title").Value, channel.Link = tag.Attributes("href").Value}
all.Add(info!Station, info.Item("Shows"))
theShows = all.Item("Shows") '<--Doesnt work...
我只想提取无论是在“显示” 从所有字典。
@LarsTech在代码中添加了该部分。对不起,离开了! – StealthRT
'all.Add(info!Station,info.Item(“Shows”))' - 与您的风格保持一致,不要在同一个语句中更改项目访问的语法!事实上,不要使用'.Item(...)'方法,要么写'info!shows'或'info(“Shows”)''。但是,要保持一致,不要混用风格。 –
当您声明字典时,对象是KEY,VALUE。在你的代码中,你的键是字符串,它会输出一个对象。当您执行“theShows = all.Item(”shows“)”时,您要求拉动与“演出”键关联的对象。这是你的意图吗?因为“显示”似乎是一个IEnumerable,并且您试图将其分配给一个String变量。 – Joe