List of keys in a JScript object using VBScript (classic ASP)

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

I want to parse all the keys, however I do not know the key names.

How can I do it?

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

thanks

+4
source share
1 answer

You need to list the property names of the object, but this is a very alien thing in VBScript. You will need to create some other Jscript functions to help convert the object to something more easily consumed in VBScript.

If the data is really as simplified as the example in the question, you can 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 
+3
source

All Articles