0

嘿,我正在尝试使用以下内容循环遍历 json 响应:

Dim url As String = "https://www.[site here].com/api/v1/messages.json?access_token=" & yAPI.userToken
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim o As JObject = JObject.Parse(reader.ReadToEnd)

reader.Close()
response.Close()

Dim mtemp As String = DirectCast(o("messages")(0)("body")("rich").ToString(), String)

我可以为mtemp获得很好的数据,但它只获得第一组,而不是循环遍历所有其余的 json 共振。

响应示例如下:

{
   json data here...
},
"threaded_extended": {},
  "messages": [
    {
      "network_id": [edited here],
      "chat_client_sequence": null,
      "privacy": "public",
      "body": {
        "urls": [
          "[edited here]"
        ],
        "rich": "[edited here]",
        "plain": "[edited here]",
        "parsed": "[edited here]"
      },
      "sender_id": [edited here],
      "content_excerpt": "[edited here]",
      "client_url": "[edited here]",
      "client_type": "Web",
      "web_url": "[edited here]",
      "created_at": "2013/08/26 19:31:50 +0000",
      "language": null,
      etc etc...................
    },
    {
      "network_id": [edited here],
      "chat_client_sequence": null,
      "privacy": "public",
      "body": {
        "rich": "[edited here]",
        "plain": "[edited here]",
        "parsed": "[edited here]"
      },
      "sender_id": [edited here],
      "content_excerpt": "[edited here]",
      "client_url": "[edited here]",
      "web_url": "[edited here]",
      "client_type": "Web",
      "created_at": "2013/08/26 19:25:00 +0000",
      "language": null,
      etc etc....
    },

我怎样才能继续循环,直到它到达我正在寻找的最后一刻?

4

1 回答 1

2

o("messages")是 a JArray,所以你可以枚举它。在您的代码中,您只要求第一项。如果你想循环,你需要一个循环结构。

For Each msg As JObject In o("messages")
    ' Do something with each msg
    Debug.WriteLine(msg("body")("rich").ToString())
Next
于 2013-08-26T21:01:06.120 回答