JSON.net - 使用VB.NET无法迭代结果

时间:2014-02-11 18:04:01

标签: asp.net json vb.net json.net

我正在尝试使用JSON.NET处理this json document

使用VB.NET代码:

        Dim o As JObject = JObject.Parse(json)
        Dim results As List(Of JToken) = o.Children().ToList

        Dim count As Integer = 0
        For Each item As JProperty In results
            Dim snippet As String = String.Empty
            Dim URL As String = String.Empty
            Dim source As String = String.Empty
            item.CreateReader()
            Select Case item.Name
                Case "response"
                    snippet = item.Last.SelectToken("docs").First.Item("snippet").ToString
                    URL = item.Last.SelectToken("docs").First.Item("web_url").ToString
                    source = ControlChars.NewLine & "<font size='2'>" & item.First.SelectToken("docs").First.Item("source").ToString & "</font>" & ControlChars.NewLine
                    tbNews.Text &= "<a href=" & URL & " target='new'>" & snippet & "</a> - " & source
            End Select
        Next

我只收到第一份文件。有人可以建议我如何将第1个 - 第N个文件作为完整清单吗?

1 个答案:

答案 0 :(得分:1)

文档深度为2级,您只是在顶层循环。试试这个......

Dim parsedObject = JObject.Parse(json)
Dim docs = parsedObject("response")("docs")

For Each doc In docs
    Dim snippet As String = doc("snippet")
    Dim URL As String = doc("web_url")
    Dim source As String = doc("source")

    '....

Next