ASP JSON:对象不是集合

ASP JSON:对象不是集合,json,object,collections,vbscript,asp-classic,Json,Object,Collections,Vbscript,Asp Classic,我应该如何从这个JSON中检索Pitchrid?我正在使用来自的类 JSON [ { "PitcherID": "456068" }, { "PitcherID": "431148" } ] 代码 oJSON.loadJSON("...") For Each thing In oJSON.data("PitcherID") Set this = oJSON.data("PitcherID").item(thing) response.write this.it

我应该如何从这个JSON中检索Pitchrid?我正在使用来自的类

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,那么这可能会导致问题,但是您可以使用
eg在另一个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>

瓦奥杰森=[
{
“Pitchrid”:“456068”
},
{
“Pitchrid”:“431148”
}
]
var strout=“”
对于(我在oJSON)
{ 
strout=strout+((oJSON[i].Pitchrid)+“
”; }
问题在于,我们的课程有限,我个人一直很难找到合适的例子来说明如何使用它

为什么得到的
对象不是集合
错误? 它非常简单,实际上,您试图像数组/集合一样迭代的对象不是一个

这条线

对于oJSON.data(“Pitchrid”)中的每一项内容 将失败,因为
oJSON.data(“pitchrid”)
不是一个集合对象,这意味着您无法遍历它。对于可枚举的
pitchrid
,源JSON结构看起来更像这样

{
“猪笼草”:[
"456068",
"431148"
]
}
比如说


链接

我需要使用与上面代码类似的东西。我将解析JSON,然后将其存储在一个数据库中,该数据库不会解释OP get为何会出现错误。错误是告诉您,您试图作为集合读取的对象我猜对于oJSON.data(“Pitchrid”)中的每一项,都是
oJSON.data(“Pitchrid”)中的
不是一个集合对象,在本例中,
pitchrid
不是,如果您查看JSON结构。那么如何将投手ID写入我的页面?@localhost您的顶级是一个数组(未命名)。您可以控制JSON结构吗?如果是这样,请修改JSON,使其包含具有命名集合的顶级对象,类似于
数据:[{“Pitchrid”:“456068”}、{“Pitchrid”:“431148”}]。然后,您应该能够在一个
For
循环中调用它,就像对oJSON.data(“data”)
中的每件事调用
,并使用您现有的代码。