views:

370

answers:

1

Hello,

I am using the JSON2 script in an asp page to parse JSON post data. After parsing the data, I have an object in VBScript that allows for notations such as: jsonData.key

I wish to parse through all the keys, however, I have no knowledge of the key names.

How would I go about doing this?

Example JSON: { "dbtable":"TABLE1", "dbcommand": "INSERT", "dbfilter": "ID" }

Thanks

+2  A: 

You need to enumerate the property names of the object however this is a very alien thing to do in VBScript. You will need to build some other Jscript functions to assist converting the object into something more easily consumed in VBScript.

If the data is really as simplistic as the example in the question then you could use this function:-

function toDictionary(o)
{
     var result = Server.CreateObject("Scripting.Dictionary");
     for (var key in o)
         result.Add(key, o[key]);
     return result;
}

Now in VBScript:-

Dim myData: Set myData = toDictionary(jsonData);

For Each Key In myData
   '' // Each Key is a property for jsonData
Next
AnthonyWJones
Dictionary object worked perfect - didn't know you could use the dictionary object like that in JScript. Thanks.One note: The For Each Key did not work. I had to store the keys and items in arrays and then do a For i=0 to myData.Count-1
Mervyn
@Mervyn: You would be better off specifying why For Each Key didn't work? Storing the keys and items in arrays is just plain ulgy, awkward and just the sort of thing the Dictionary object is designed to handle.
AnthonyWJones