无法从网页中获取 json 格式的数据

SIM卡

在运行我的 vba 脚本以解析网页中的数据后,我可以看到它显示“需要对象”错误。我可以在导致错误的行之前设置的 msgbox 中看到所需的数据。由于我还没有使用过 json 格式,所以我无法成功执行。任何帮助,将不胜感激。这是我要做的:

Sub JsonData()
Dim http As New MSXML2.XMLHTTP60
Dim PostData As String, JSONa As Object, ele As Object

PostData = "region=US&latitude=61.7958256&longitude=-148.8045856&location=Sutton-Alpine%2C%20AK&source=US-STANDALONE&radius=25&pageNumber=1&pageSize=10&sortBy=&industryFilter=340&serviceFilter=550,90"

With http
    .Open "GET", "https://proadvisorservice.intuit.com/v1/search?" & PostData, False
    .setRequestHeader "Content-Type", "application/json; charset=utf-8"
    .setRequestHeader "Accept", "application/json;version=1.1.0"
    .send
    Set JSONa = JsonConverter.ParseJson(.responseText)
End With
MsgBox http.responseText
    For Each ele In JSONa
        i = i + 1
        Cells(i, 1).Value = ele("firstName")
        Cells(i, 2).Value = ele("lastName")
        Cells(i, 3).Value = ele("city")
    Next ele
End Sub
丹尼尔·杜塞克

搜索结果是VBA.Collection此集合的每个项目包含然后另一个Scripting.Dictionary希望您所要求的是以下内容。HTH

Dim results As VBA.Collection
Set results = JSONa("searchResults")

Dim result As Scripting.Dictionary
For Each result In results
    i = i + 1
    Cells(i, 1).Value = result("firstName")
    Cells(i, 2).Value = result("lastName")
    Cells(i, 3).Value = result("city")
Next result

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章