【问题标题】:How can I read a HTTP-header while making an API call from Excel VBA using JSON?如何在使用 JSON 从 Excel VBA 进行 API 调用时读取 HTTP 标头?
【发布时间】:2017-09-14 08:31:47
【问题描述】:

我正在使用此 JsonConverter 从 Excel VBA 对服务器进行 API 调用:

*) https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas

我使用这个命令很好用:

http.Open "GET", APIString, False
http.send    
Set JSON = ParseJson(http.responseText)

虽然在某些情况下接收到的 JSON 字符串已损坏并且我的代码因错误而停止。

如果我是正确的,应该有一个“http-header”,其中包含一个数字,表示 JSON 字符串已损坏。

你知道我可以在哪里以及如何从 Excel VBA 导入这个“http-header”。在这种情况下,我可以取消我的 API 调用,标题中的数字表示内容已损坏。

谢谢!

【问题讨论】:

    标签: json vba excel


    【解决方案1】:

    检查您的 http 请求的状态:

    if http.Status = 200 Then
        Set JSON = ParseJson(http.responseText)
    else
        ' ... (error handling)
    end if
    

    【讨论】:

    • 谢谢托马斯,我会添加这些行。
    猜你喜欢
    • 2011-01-23
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 2014-06-26
    • 2019-06-21
    相关资源
    最近更新 更多