下面的示例...从解析的JSON字符串循环对象返回错误"对象不支持此属性或方法".任何人都可以建议如何使这项工作?非常感谢(我在这里问了6个小时寻找答案).
用于将JSON字符串解析为对象的函数(这可以正常工作).
Function jsonDecode(jsonString As Variant)
Set sc = CreateObject("ScriptControl"): sc.Language = "JScript"
Set jsonDecode = sc.Eval("(" + jsonString + ")")
End Function
Run Code Online (Sandbox Code Playgroud)
循环解析对象将返回错误"对象不支持此属性或方法".
Sub TestJsonParsing()
Dim arr As Object 'Parse the json array into here
Dim jsonString As String
'This works fine
jsonString = "{'key1':'value1','key2':'value2'}"
Set arr = jsonDecode(jsonString)
MsgBox arr.key1 'Works (as long as I know the key name)
'But this loop doesn't work - what am I doing wrong?
For Each keyName In arr.keys 'Excel errors out …
Run Code Online (Sandbox Code Playgroud) 我在VBScript中有以下代码:
Dim control
set control = CreateObject("MSScriptControl.ScriptControl")
control.language = "jscript"
control.addCode("function test() { return {property: 'test'}; };")
Dim result
set result = control.Eval("test();")
Run Code Online (Sandbox Code Playgroud)
我知道返回的对象result
属于该类型JScriptTypeInfo
但我无法找到有关此类型定义的任何信息,并且在Visual Studio C#中执行类似的代码仅{System.__ComObject}
在本地窗格中显示此内容.
有谁知道该JScriptTypeInfo
类型的接口是什么?