解析 Json string vb6 [duplicate]

Parsing Json string vb6 [duplicate]

提问人:user1579247 提问时间:6/14/2023 最后编辑:Étienne Lanevilleuser1579247 更新时间:6/15/2023 访问量:97

问:

我检索 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

到最后我在 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}

如何从 Json 节点获取所有值?

JSON API VB6

评论

0赞 Tim Williams 6/14/2023
标题显示 VB6,但您的问题也带有 VBA 标签?它是什么?对于 VBA,可以使用 github.com/VBA-tools/VBA-JSON
1赞 Brian M Stafford 6/15/2023
看看这个答案
0赞 user1579247 6/16/2023
我无话可说,谢谢你,救了我!

答:

1赞 Brian M Stafford 6/15/2023 #1

下载 VB-JSON:Visual Basic 6 (VB6) JSON 分析器类库,并将必要的项添加到项目中。添加后,您可以像这样解析 JSON 字符串:

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

您可以检索如下值

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")

或者,如果要遍历这些项目,请执行如下操作:

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

评论

0赞 user1579247 6/16/2023
我无话可说,谢谢你,救了我!