JSON.net 循环通过 facebook json 数组 [英] JSON.net loop through facebook json array
问题描述
嘿,我想弄清楚如何遍历一个看起来像这样的 JSON 数组:
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.....
从上面的例子来看,只有 "data": 出现了一次,所以我不能用它作为循环到下一个故事的手段.如您所见,故事从 "id": 开始,一直到 "updated_time":.然后接下来的故事从 "id": 开始,一直到 "updated_time":.
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.
我正在使用以下代码:
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)
我可以很好地获取我需要的值,但它不会循环获取所有其他值,而不是检索第一个值.
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.
我尝试过这样的代码:
For Each Row In json("id")(0)("id")
MsgBox("here")
Next Row
但这似乎并没有做任何事情,只是在 json("id")(0)("id")
But that doesnt seem to do anything but error out at the json("id")(0)("id")
推荐答案
我认为您正在寻找:
For Each Row In json("data")
Console.WriteLine(Row("id"))
Console.WriteLine(Row("type"))
' etc...
Next
基本上,获取 JSON 中 data
属性对应的数组并迭代其成员.
Basically, grab the array that the data
property corresponds to in the JSON and iterate over its members.
这篇关于JSON.net 循环通过 facebook json 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!