嘿所有我想弄清楚如何循环看起来像这样的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")
答案 0 :(得分:2)
我认为您正在寻找:
For Each Row In json("data")
Console.WriteLine(Row("id"))
Console.WriteLine(Row("type"))
' etc...
Next
基本上,抓取data
属性在JSON中对应的数组并迭代其成员。