JSON.net loop through facebook json array

Solution for JSON.net loop through facebook json array
is Given Below:

Hey all I am trying to figure out how to loop through a JSON array that looks like this:

{
  "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.....

From the example above, only “data”: shows up once so I can not use that as the means to loop to the next story. As you see the story starts at “id”: and goes all the way to “updated_time”:. Then the next story to follow that one starts at “id”: and goes all the way to “updated_time”: as well.

I am using this code below:

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)

I can get the values I am in need of just fine, but it doesn’t loop to get all the other ones past retrieving the first one.

I tried code like this:

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

But that doesnt seem to do anything but error out at the json(“id”)(0)(“id”)

I think you’re looking for:

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

Basically, grab the array that the data property corresponds to in the JSON and iterate over its members.