【问题标题】:Looping through JSON Array using ASPJSON使用 ASPJSON 循环遍历 JSON 数组
【发布时间】:2015-06-12 12:03:39
【问题描述】:

感谢此处 (Looping through JSON using ASPJSON) 和此处 (ASP JSON: Object not a collection) 的建议,我开始使用 Classic ASP 中的 JSON 数组:

{"markers": [{
  "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 和 ASPJSON (http://www.aspjson.com/)。

我可以通过以下方式从循环中访问“_id”和“ts”值:

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

但是,我在“msg”部分中试图获取下一层的数据。

我试过了:

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

但是得到这个错误:

描述:对象不是集合:.

关于这一行:

对于oJSON.data("msg")中的每个thingy2

我想我在做一些愚蠢的事情,但我被困在这个问题上,无法弄清楚如何访问该数据。

【问题讨论】:

    标签: json asp-classic


    【解决方案1】:

    您可以在已有的循环中访问 msg,这是一个 json 对象:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-22
      • 2013-08-16
      • 2011-06-11
      相关资源
      最近更新 更多