1

こんにちは、辞書リストをループする助けが必要です。そうするための正しい構文が見つからないようです。

これが私のコードです:

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...

すべての辞書から「ショー」にあるものをすべて抽出したいだけです。

ここに画像の説明を入力

4

2 に答える 2

1

このようにループできます

For Each pair As KeyValuePair(Of String, String) In dict

    MsgBox(pair.Key & "  -  " & pair.Value)
Next

ソース: VB.Net 辞書

ウィンストン

于 2014-02-17T07:23:43.290 に答える
1

あなたのコード、

all.Add(info!Station, info.Item("Shows"))

theShows = all.Item("Shows")

の値が辞書info!Stationの KEY 値として使用されています。all次に、定数 string を使用して値にアクセスしようとします"Shows"。あなたの意図が何だったのかはわかりませんが、

theShows = all.Item(info!Station)

ShowsKey を使用して格納された値を返す必要がありますinfo!Station

ショーのリストを文字列として表示したい場合は、次のようにします。

Dim Shows as String = ""
For Each item in theShows
    Shows &= item.Show & vbNewLine
Next
于 2012-11-01T14:30:16.323 に答える