1

I'm getting below type of responses from an API:

"{"success":false,"error":"Incorrect apikey"}"

"{"success":true,"error":"Correct apikey"}"

In VBA, how to know if response is true or false ?

My current code is below and am getting response in hReq.ResponseText and it is not always fixed (more keys can be added to json). Although the part below is fixed and I have to get only if it returning true or false.

"{"success":false

Code:

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

I know this is basic question but sorry am new to VBA.

Community
  • 1
  • 1
Softhmak.
  • 131
  • 9
  • Possible duplicate of [How to parse JSON with VBA without external libraries?](https://stackoverflow.com/q/19360440/11683) – GSerg Sep 08 '18 at 13:45

1 Answers1

0

Purely based on what you have shown you can get True/False with

Split(Split(hReq.ResponseText, ":")(1), ",")(0)
QHarr
  • 83,427
  • 12
  • 54
  • 101