下午好,我正在使用 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 节点。
我已经尝试了多种方法,但总是有错误。如何从经典asp中主json(嵌套json)内的节点获取值?
谢谢。
最佳答案
扩展在 my previous comment :
Would it not be to use a
For Each
statement to loop throughPax("opcionais_bilhete").items
as it's aJSONarray
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
关于arrays - 使用 ASP Classic 和 aspJSON 获取嵌套的 json 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60973439/