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
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">
egThe problem is the class from http://aspjson.com is limited and personally I've always found it hard to find decent examples of how to use it.
Why do you get the
Object not a collection
error?It's quite simple really the object you are trying to iterate through like an array / collection is not one.
This line
will fail because
oJSON.data("PitcherID")
is not a collection object which means you cannot iterate through it. ForPitcherID
to be enumerable the source JSON structure would look more like thisfor example.
Links