JSON.net通过facebookjson数组循环



嘿,我正试图弄清楚如何在JSON数组中循环,它看起来像这样:

{
  "data": [
    {
      "id": "1zzz87_1020zzzzzzz9403", 
      "from": {
        "id": "10zzzzzz487", 
        "name": "Tom zzzzz"
      }, 
      "story": "Tom zzzz shared YouVersion's photo.", 
      "picture": "https://fbcdn-sphotos-a-a.akamaihd.net/zzzzz/4948_n.jpg?xxx_210ce5zzzza8b3e", 
      "link": "https://www.facebook.com/YouVersion/photos/zzzz/?type=1", 
      "name": "Mobile Uploads", 
      "caption": "1 John 4:4 NASB", 
      "properties": [
        {
          "name": "By", 
          "text": "YouVersion", 
          "href": "https://www.facebook.com/YouVersion?ref=stream"
        }
      ], 
      "icon": "https://fbstatic-a.akamaihd.net/zzzzz.gif", 
      "actions": [
        {
          "name": "Comment", 
          "link": "https://www.facebook.com/1020zzzzz48z/posts/102zzzzzz79zzz43"
        }, 
        {
          "name": "Like", 
          "link": "https://www.facebook.com/102zzz33zz/posts/102zzzzz40279zz3"
        }
      ], 
      "privacy": {
        "value": ""
      }, 
      "type": "photo", 
      "status_type": "shared_story", 
      "object_id": "101zzzzzz2", 
      "application": {
        "name": "Facebook for iPhone", 
        "namespace": "fbiphone", 
        "id": "6zzzzzz9"
      }, 
      "created_time": "2014-09-21T02:04:20+0000", 
      "updated_time": "2014-09-21T02:04:20+0000"
    }, 
    {
      "id": "1zzzzzzz487_102zzzzzz3zz82", 
      "from": {
        "id": "1020431zzzzzz", 
        "name": "Tom zzzzzz"
      }, 
      "story": "Tom zzzzz shared Brian zzzzzz's photo.", 
      etc etc.....

从上面的例子中,只有"data":出现一次,所以我不能用它作为循环到下一个故事的手段。正如您所看到的,故事从"id":开始,一直到的"updated_time":接下来的下一个故事从"id":开始,一直到的"updated_time":

我使用以下代码:

Dim strJson As String       = File.ReadAllText("D:winDataMy DocumentsjsonTEST.json")
Dim json As JObject         = JObject.Parse(strJson)
Dim thePostID As String     = DirectCast(json("data")(0)("id").ToString(), String)
Dim thePostType As String   = DirectCast(json("data")(0)("type").ToString(), String)
Dim thePosterID As String   = DirectCast(json("data")(0)("from")("id").ToString(), String)
Dim thePosterName As String = DirectCast(json("data")(0)("from")("name").ToString(), String)
Dim thePostTitle As String  = DirectCast(json("data")(0)("story").ToString(), String)

我可以很好地获得我需要的值,但它不会循环以使所有其他值都通过检索第一个值。

我试过这样的代码:

For Each Row In json("id")(0)("id")
   MsgBox("here")
Next Row

但这似乎没有任何作用,只是在json("id")(0)("id")

处出错

我想您正在寻找:

For Each Row In json("data")
    Console.WriteLine(Row("id"))
    Console.WriteLine(Row("type"))
    ' etc...
Next

基本上,获取JSON中data属性对应的数组,并对其成员进行迭代。

相关内容

  • 没有找到相关文章

最新更新