问题描述
我使用传统的ASP和ASPJSON(),尝试通过JSON测试数据环通过山魈网络挂接回来了。
I am using Classic ASP and ASPJSON (http://www.aspjson.com/) to try to loop through JSON test data returned via a Mandrill Webhook.
这是示例JSON数据 - 我认识的第二块是一样的第一,但我需要使用它,因为我做这个活的系统网络挂接数据将分批在一个JSON文件被退回的时候/后。
This is the sample JSON data - I realise the 2nd block is the same as the first, but I need to use it since when I do this on the live system the webhook data will be returned in batches in a single JSON file / post.
{
"event":"hard_bounce",
"msg":{
"ts":1365109999,
"subject":"This an example webhook message",
"email":"example.webhook@mandrillapp.com",
"sender":"example.sender@mandrillapp.com",
"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":"example.webhook@mandrillapp.com",
"sender":"example.sender@mandrillapp.com",
"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页,我想一个简单的测试(我已经证实了JSON数据是有效的通过将其保存到数据库并检查内容)
In my test ASP page, I tried a simple test (I have already confirmed the JSON data is valid by saving it to a database and checking the content)
<!--#INCLUDE file="aspJSON.asp" -->
str2 = <POST DATA FROM MANDRILL>
Set oJSON = New aspJSON
oJSON.loadJSON(str2)
Response.Write oJSON.data("event") & "<hr>"
response.write "<h1>test</h1>"
For Each phonenr In oJSON.data("msg")
Set this = oJSON.data("msg").item(phonenr)
Response.Write _
this.item("subject") & ": " & _
this.item("diag") & "<br>"
Next
当山魈调用ASP页面,则返回这个错误:
When Mandrill calls the ASP page, it returns this error:
说明:对象不是一个集合。
Description: Object not a collection : .
有关这一行:
对于每个phonenr在oJSON.data(味精)
For this line:For Each phonenr In oJSON.data("msg")
我坚持工作如何,对每个事件,我可以循环遍历并从味精和_id值获得的属性以及
I am stuck working out how, for each event, I can loop through it and get the attributes from "msg" and the "_id" value as well.
推荐答案
裹的STR2因此,它是一个有效的JSON收集和更新您的code到如下遍历该集合。
Wrap the str2 so that it is a valid JSON collection and update your code to iterate that collection as below.
<!--#INCLUDE file="aspJSON.asp" -->
str2 = <POST DATA FROM MANDRILL>
' Wrap str2 to turn it into a collection
str2 = "{""events"":[" & str2 & "]}"
Set oJSON = New aspJSON
oJSON.loadJSON(str2)
response.write "<h1>test</h1>"
For Each eventrec In oJSON.data("events") ' Iterate through events
Set this = oJSON.data("events").item(eventrec).item("msg") ' select msg in each eventrec
Response.Write _
this.item("subject") & ": " & _
this.item("diag") & "<br>"
Next
这篇关于通过使用JSON ASPJSON循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!