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

问题描述 投票:1回答:1

下午好,我正在使用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)内部的节点获取值?

谢谢。

arrays json vbscript asp-classic
1个回答
1
投票

展开my previous comment

不是因为它是For Each对象,所以不使用Pax("opcionais_bilhete").items语句循环遍历JSONarray吗?

这对我有用。

<%
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
© www.soinside.com 2019 - 2024. All rights reserved.