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?

Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
user1579247
  • 107
  • 1
  • 6

1 Answers1

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
Brian M Stafford
  • 8,483
  • 2
  • 16
  • 25