我正在开发一个经典的ASP项目,我使用ASP Xtreme Evolution来解析JSon数据(在这里找到:How to access JSON data in classic ASP using json2.asp or aspjson libraries?) 我试过了,但我做不到。我如何访问这个json数据?
{
"result":[
{
"key":"2607037",
"sts":"finished",
"stsdetail":"Finished",
"sname":"Ice Hockey",
"home":{
"1p":"0",
"fe":"2",
"3p":"1",
"2p":"1",
"ord":"2",
"rs":"2"
},
"away":{
"ord":"0",
"1p":"0",
"rs":"0",
"2p":"0",
"3p":"0",
"fe":"0"
}
},
{
"key":"2435948",
"sts":"finished",
"stsdetail":"Finished",
"sname":"Soccer",
"home":{
"ord":"2",
"rs":"2",
"fe":"2",
"ht":"1"
},
"away":{
"ord":"0",
"rs":"0",
"fe":"0",
"ht":"0"
}
},
{
"key":"2606031",
"sts":"cancelled",
"stsdetail":"Cancelled",
"sname":"Tennis"
}
]
}
代码:
set restaurant = oJSON.data("result")
for each itm in restaurant
if Not IsObject(restaurant.item(itm)) then
Response.write itm &" : "& restaurant.item(itm) & "<br/>"
else
'opening
for each dayy in restaurant.item(itm)
Response.write dayy & ":"
Response.write restaurant.item(itm)(dayy)
If restaurant.item(itm)(dayy) <> "" Then
Response.write " - "
Response.write restaurant.item(itm)(dayy)
End If
Response.write "<br/>"
next
end if
答案 0 :(得分:1)
你错过了数组中的索引,试试这个:
for each dayy in restaurant.item(itm)
Response.write dayy & ":"
Response.write restaurant.item(itm)(dayy)(0)
If restaurant.item(itm)(dayy)(1) <> "" Then
Response.write " - "
Response.write restaurant.item(itm)(dayy)(1)
End If
Response.write "<br/>"
next