问题描述
由于建议从这里(<一href=\"http://stackoverflow.com/questions/30782144/looping-through-json-using-aspjson?noredirect=1#comment49615942_30782144\">Looping通过使用ASPJSON )和这里(),我开始与经典ASP JSON数组:
Thanks to advice from here (Looping through JSON using ASPJSON) and here (ASP JSON: Object not a collection), I am starting with a JSON array in Classic ASP:
{"markers": [{
"event":"hard_bounce",
"msg":{
"ts":1365109999,
"subject":"This an example webhook message",
"email":"[email protected]",
"sender":"[email protected]",
"tags":[
"webhook-example"
],
"state":"bounced",
"metadata":{
"user_id":111
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
"_version":"exampleaaaaaaaaaaaaaaa",
"bounce_description":"bad_mailbox",
"bgtools_code":10,
"diag":"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces."
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
"ts":1433940242
},
{
"event":"hard_bounce",
"msg":{
"ts":1365109999,
"subject":"This an example webhook message",
"email":"[email protected]",
"sender":"[email protected]",
"tags":[
"webhook-example"
],
"state":"bounced",
"metadata":{
"user_id":111
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
"_version":"exampleaaaaaaaaaaaaaaa",
"bounce_description":"bad_mailbox",
"bgtools_code":10,
"diag":"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces."
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
"ts":1433940242
}]
}
我使用传统的ASP和ASPJSON()。
我可以访问_id和TS通过从循环值:
I can access the "_id" and "ts" values from the loop via:
Set oJSON = New aspJSON
'read the local JSON data
oJSON.loadJSON(str2)
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>"
Next
不过,我坚持尝试在数据获得下一层的味精部分。
However, I am stuck trying to get at the data one level down, in the "msg" section.
我也尝试:
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>"
For Each thingy2 In oJSON.data("msg")
Set this2 = oJSON.data("this2").item(thingy2)
Response.Write _
this2.item("subject") & ": " & _
this2.item("diag") & "<br>"
Next
Next
但得到这个错误:
But get this error:
说明:对象不是一个集合:
有关这一行:
有关每个thingy2在oJSON.data(味精)
For Each thingy2 In oJSON.data("msg")
我想我做一些很傻,但我被困在这一个,并可以不知道如何访问这些数据。
I guess I am doing something silly, but I am stuck on this one and can't work out how to access that data.
推荐答案
您可以访问信息
,这是一个JSON对象,你已经在循环中:
You could access msg
, which is a json object, within the loop you already have:
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>" &_
this.item("msg").item("subject") & ": " &_
this.item("msg").item("diag") & "<br>"
Next
这篇关于通过使用JSON ASPJSON循环数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!