【问题标题】:VBA Parse String Response From APIVBA 解析来自 API 的字符串响应
【发布时间】:2018-09-08 13:43:12
【问题描述】:

我从 API 收到以下类型的响应:

"{"success":false,"error":"不正确的 apikey"}"

"{"success":true,"error":"正确的 apikey"}"

在VBA中,如何知道响应是真还是假?

我当前的代码在下面,并且在 hReq.ResponseText 中得到响应,并且它并不总是固定的(可以向 json 添加更多键)。虽然下面的部分是固定的,我只有在它返回 true 或 false 时才能得到。

"{"成功":false

代码:

Dim hReq As Object
Dim strUrl As String
strUrl = "https://myWebAPI/myMethod?apikey=123456"

Set hReq = CreateObject("MSXML2.XMLHTTP")
With hReq
    .Open "GET", strUrl, False
    .Send
End With

MsgBox hReq.ResponseText

我知道这是基本问题,但很抱歉我是 VBA 新手。

【问题讨论】:

标签: json vba excel http


【解决方案1】:

完全基于你所展示的你可以得到真/假

Split(Split(hReq.ResponseText, ":")(1), ",")(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 2014-11-12
    • 1970-01-01
    • 2020-05-20
    • 2014-01-21
    • 2017-06-14
    相关资源
    最近更新 更多