使用VBScript JScript中的对象列表键(经典ASP) [英] List Keys in JScript object using VBScript (Classic ASP)

查看:203
本文介绍了使用VBScript JScript中的对象列表键(经典ASP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP页的JSON2脚本解析JSON后的数据。
分析数据后,我已经在VBScript中的对象,允许符号,如:
jsonData.key

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.

我怎么会去这样做?

例如JSON:
{DBTABLE:TABLE1,的DbCommand:插入,dbfilter:ID}

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

感谢

推荐答案

您需要枚举对象的属性名称然而,这是在VBScript中做一个非常陌生的东西。您将需要建立一些其他的JScript函数,以协助对象转换成东西在VBScript中更容易消耗掉。

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;
}

在VBScript

现在: -

Now in VBScript:-

Dim myData: Set myData = toDictionary(jsonData);

For Each Key In myData
   '' // Each Key is a property for jsonData
Next

这篇关于使用VBScript JScript中的对象列表键(经典ASP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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