ASP JSON:对象不是集合 [英] ASP JSON: Object not a collection

查看:18
本文介绍了ASP JSON:对象不是集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

JSON

<预><代码>[{投手ID":456068"},{投手ID":431148"}]

代码

oJSON.loadJSON("...")对于 oJSON.data("PitcherID") 中的每件事设置这个 = oJSON.data("PitcherID").item(thing)response.write this.item("PitcherID")下一个

错误

Microsoft VBScript 运行时错误800a01c3"对象不是集合

解决方案

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

<%@language="javascript"%><!DOCTYPE html><身体><%var oJSON =[{投手ID":456068"},{投手ID":431148"}]对于(我在 oJSON 中){Response.write((oJSON[i].PitcherID) + "
");}%>

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

<%@language="VBScript"%><!DOCTYPE html><头><script language="javascript" runat="server">var oJSON =[{投手ID":456068"},{投手ID":431148"}]var strout = ""对于(我在 oJSON 中){strout = strout + ((oJSON[i].PitcherID) + "
");}<身体><% Response.write strout %>

How should I retrieve PitcherID from this JSON? I am using the class from http://aspjson.com.

JSON

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

Code

oJSON.loadJSON("...")

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

Error

Microsoft VBScript runtime error '800a01c3'

Object not a collection

解决方案

In my experience it's far easier to just use JScript as your server side scripting language than to use the aspjson class. You could render your JSON object as follows

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


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

</body>
</html>

I realise that this may cause problems if the json processing is only part of a page and the rest of it uses VBScript, however you can execute server side JS in what is otherwise a VBS page by using <script runat="server"> eg

<%@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>

这篇关于ASP JSON:对象不是集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆