2014-09-24 152 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