gpt4 book ai didi

json - ASP JSON : Object not a collection

转载 作者:行者123 更新时间:2023-12-05 07:07:37 33 4
gpt4 key购买 nike

我应该如何从这个 JSON 中检索 PitcherID?我正在使用 http://aspjson.com 中的类(class)。

JSON

[
{
"PitcherID": "456068"
},
{
"PitcherID": "431148"
}
]

代码

oJSON.loadJSON("...")

For Each thing In oJSON.data("PitcherID")
Set this = oJSON.data("PitcherID").item(thing)
response.write this.item("PitcherID")
Next

错误

Microsoft VBScript runtime error '800a01c3'

Object not a collection

最佳答案

根据我的经验,使用 JScript 作为服务器端脚本语言要比使用 aspjson 类容易得多。您可以按如下方式呈现您的 JSON 对象

<%@language="javascript"%>
<!DOCTYPE html>
<html>
<body>


<%
var oJSON =[
{
"PitcherID": "456068"
},
{
"PitcherID": "431148"
}
]
for (i in oJSON)
{
Response.write((oJSON[i].PitcherID) + "<br />");
}
%>

</body>
</html>

我意识到如果 json 处理只是页面的一部分而其余部分使用 VBScript,这可能会导致问题,但是您可以通过使用 <script runat="server"> 例如在 VBS 页面中执行服务器端 JS

<%@language="VBScript"%>
<!DOCTYPE html>
<html>
<head>

<script language="javascript" runat="server">
var oJSON =[
{
"PitcherID": "456068"
},
{
"PitcherID": "431148"
}
]
var strout = ""
for (i in oJSON)
{
strout = strout + ((oJSON[i].PitcherID) + "<br />");
}
</script>


</head>
<body>

<% Response.write strout %>

</body>
</html>

关于json - ASP JSON : Object not a collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62069157/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com