【发布时间】:2013-05-24 22:18:07
【问题描述】:
我需要处理一个 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 + "')")
我在Set sc = CreateObject("ScriptControl") 行中收到错误Run-time error '429' ActiveX component can't create object
一旦我们解析了 JSON 对象,你如何访问 JSON 对象的值?
附:我的 JSON 对象示例:{"Success":true,"Message":"Blah blah"}
【问题讨论】:
-
能否提供要拉取数据的链接和id。
-
或许可以试试
Set sc = CreateObject("MSScriptControl.ScriptControl") -
@Santosh,它不是在线链接......现在是本地主机。我没有任何在线链接可以 ping 并获得结果。
-
@barrowc 试过了。没有运气:( :(
-
要访问诸如 array.item(0) 之类的项目,请参阅此帖子stackoverflow.com/questions/5773683/…
标签: json vba excel xmlhttprequest