JSON.net解析数据



嘿,我正试图用以下内容循环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....
    },

我如何才能继续循环,直到它到达我要寻找的最后一刻?

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

For Each msg As JObject In o("messages")
    ' Do something with each msg
    Debug.WriteLine(msg("body")("rich").ToString())
Next

相关内容

  • 没有找到相关文章

最新更新