2

My code to retrieve STRINGA:

Private Sub RestExample()

    Dim APICall As String
    Dim Query As String
    Dim strKey As String, STRINGA AS STRING
    Dim myXML As New MSXML2.DOMDocument60
    Dim nodes As IXMLDOMSelection

    APICall = "https://oauth.openapi.it/counters/total"
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", APICall, False
        .setRequestHeader "Authorization", "Basic " & PASSWORD
        .send
        STRINGA = .responseText
    End With

End Sub

to the end i have in STRINGA:

{"data":{"GET:oauth.openapi.it\/counters":{"counter":22,"paid":0,"limit":false},"GET:oauth.openapi.it\/scopes":{"counter":6,"paid":0,"limit":false},"POST:oauth.openapi.it\/token":{"counter":1,"paid":0,"limit":false},"GET:imprese.openapi.it\/advance":{"counter":14,"paid":0,"limit":false},"GET:imprese.openapi.it\/base":{"counter":2,"paid":0,"limit":false}},"success":true,"message":"","error":null}

How to get all values from Json node?

3
  • Title says VB6 but your question is also tagged with VBA? Which is it? For VBA, you can use github.com/VBA-tools/VBA-JSON Commented Jun 14, 2023 at 15:32
  • 1
    Check out this answer. Commented Jun 14, 2023 at 16:20
  • I have no words to thank you, SAVED ME! Commented Jun 16, 2023 at 9:00

1 Answer 1

1

Download VB-JSON: A Visual Basic 6 (VB6) JSON Parser Class Library and add the necessary items to your project. Once added you parse the JSON string like this:

Dim p As Object
Set p = JSON.parse(STRINGA)

And you can retrieve values like this

Debug.Print p.Item("data").Item("GET:oauth.openapi.it\/counters").Item("counter")
Debug.Print p.Item("success")
Debug.Print p.Item("message")
Debug.Print p.Item("error")

Or if you want to iterate over the items do something like this:

Dim Data As Variant
Dim Item As Variant
   
For Each Data In p.Item("data").Items
   For Each Item In Data.Items
      Debug.Print Item
   Next
Next
Sign up to request clarification or add additional context in comments.

1 Comment

I have no words to thank you, SAVED ME!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.