2014-09-24 110 views
1

嘿,我试图找出如何通过JSON数组看起来像这样的循环:JSON.net循环通过Facebook 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..... 

从上面的例子中,只有“数据”:出现一次,所以我不能用它作为循环到下一个故事的手段。正如你所看到的故事开始于“id”:,并一直到“updated_time”:。然后接下来的故事开始于“id”:并且一直到“updated_time”:以及。

我使用下面这段代码:

Dim strJson As String  = File.ReadAllText("D:\winData\My Documents\jsonTEST.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”)

回答

2

我认为你正在寻找:

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

基本上,抢阵列的data属性对应于JSON和迭代其成员。

+0

你明白了,安德鲁。谢谢! – StealthRT 2014-09-24 01:55:55