相关疑难解决方法(0)

在Excel VBA中解析JSON

我有与Excel VBA相同的问题:Parsed JSON Object Loop但无法找到任何解决方案.我的JSON有嵌套对象所以像VBJSON和vba-json这样的建议解决方案对我不起作用.我还修复了其中一个正常工作,但结果是一个调用堆栈溢出,因为doProcess函数的许多递归.

最好的解决方案似乎是原始帖子中看到的jsonDecode函数.它非常快速且高效; 我的对象结构是JScriptTypeInfo类型的通用VBA对象.

此时的问题是我无法确定对象的结构是什么,因此,我事先并不知道将存在于每个通用对象中的键.我需要遍历通用VBA对象来获取键/属性.

如果我的解析javascript函数可以触发VBA函数或sub,那将是非常好的.

excel parsing vba json object

67
推荐指数
5
解决办法
13万
查看次数

Excel VBA:解析的JSON对象循环

下面的示例...从解析的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)

excel vba json scriptcontrol

21
推荐指数
2
解决办法
5万
查看次数

在Excel VBA代码中处理XMLHttp响应中的JSON对象

我需要处理一个JSON对象,它是Excel VBA中XMLHTTPRequest的响应.我写了下面的代码,但它不起作用:

  Dim sc As Object
  Set sc = CreateObject("ScriptControl")
  sc.Language = "JScript"

  Dim strURL As String: strURL = "blah blah"

  Dim strRequest
  Dim XMLhttp: Set XMLhttp = CreateObject("msxml2.xmlhttp")
  Dim response As String

  XMLhttp.Open "POST", strURL, False
  XMLhttp.setrequestheader "Content-Type", "application/x-www-form-urlencoded"
  XMLhttp.send strRequest
  response = XMLhttp.responseText
  sc.Eval ("JSON.parse('" + response + "')")
Run Code Online (Sandbox Code Playgroud)

我收到错误运行时错误'429'ActiveX组件无法在行中 创建对象Set sc = CreateObject("ScriptControl")

解析JSON对象后,如何访问JSON对象的值?

PS My JSON对象示例: {"Success":true,"Message":"Blah blah"}

excel vba json xmlhttprequest excel-vba

15
推荐指数
2
解决办法
7万
查看次数

使ScriptControl与Excel 2010 x64一起使用

我尝试使用给予解决这个,但是,每当我尝试运行最基础的东西,我得到一个Object not Defined错误.我认为这将是我的错(没有安装ScriptControl).但是,我尝试按此处所述进行安装,但无济于事.

我正在使用Office 2010 64位运行Windows 7 Professional x64.

com vba excel-vba scriptcontrol excel-2010

7
推荐指数
2
解决办法
2万
查看次数