使用 ASPJSON 循环遍历 JSON 数组 [英] Looping through JSON Array using ASPJSON

查看:28
本文介绍了使用 ASPJSON 循环遍历 JSON 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢来自这里的建议(使用 ASPJSON 循环遍历 JSON)和这里(ASP JSON:对象不是集合),我我从 Classic 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":"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/).

I am using Classic ASP and ASPJSON (http://www.aspjson.com/).

我可以通过以下方式从循环中访问_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

但是,我无法在msg"部分中获取下一级的数据.

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

但是得到这个错误:

描述:对象不是集合:.

Description: Object not a collection : .

关于这一行:

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

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.

推荐答案

您可以在已有的循环中访问 msg,这是一个 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

这篇关于使用 ASPJSON 循环遍历 JSON 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆