使用 ASP Classic 和 aspJSON 获取嵌套的 json 值

Get nested json value using ASP Classic and aspJSON

下午好,我正在使用 aspJSON (https://github.com/rcdmk/aspJSON) 分析下面的 json:

{
   "pedido":1507WSC,
   "destino":"Brasil",
   "Passageiros":[
      {
         "bilhete":150WDE,
         "valor_seguro":0.0,
         "opcionais_bilhete":[
            {
               "tipo":"OET",
               "codigo":1502,
               "nome":"Esportiva",
               "valor":15.00
            }
         ],
         "codigo":528XCV,
      }
   ],
   "opcionais":null,
   "data_viagem":null
}

我正在使用下面的 ASP 代码来获取一些信息。

Response.LCID = 1043

Dim objVoucher
Dim objJson : Set objJson = New JSONobject

Set objVoucher = objJson.parse(MyJasonTextHere)

Dim Pax

For Each Pax in objVoucher("Passageiros").items
        response.write (Pax.value("bilhete"))
Next

结果是150WDE。目前为止是正确的。

但是,现在我需要获取包含在 opcionais_bilhete 节点中的 tipo 参数中包含的信息.

我尝试了多种方法,但总是出错。如何从经典 asp 中主 json(嵌套 json)内的节点获取值?

谢谢。

上扩展:

Would it not be to use a For Each statement to loop through Pax("opcionais_bilhete").items as it's a JSONarray object?

这对我有用。

<%
Response.LCID = 1043

Dim objVoucher
Dim objJson : Set objJson = New JSONobject

Set objVoucher = objJson.parse(json)

Dim Pax, Op

For Each Pax in objVoucher("Passageiros").items
  Call Response.Write(Pax.value("bilhete") & "<br />")
  'Loop through the "opcionais_bilhete" JSONarray
  For Each Op in Pax("opcionais_bilhete").items
    Call Response.Write(Op.value("tipo"))
  Next
Next
%>

输出:

150WDE
OET