ASP JSON: 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>

Leave a Comment