0

我正在使用中提到的解析器:Is There a JSON Parser for VB6 / VBA? 但我在获取嵌套数组的值时遇到问题。这是我拥有的 JSON 字符串(来自网络服务的响应,我对其进行了验证,它是有效的 JSON):

Dim stJsonResponse As String
stJsonResponse = {"stat":"ok","list":[{"url":["http://www.worldcat.org/oclc/69935068?referer=xid"],"publisher":"Tascabili Economici Newton","form":["BA"],"lang":"ita","city":"Milano","author":"Kahlil Gibran; org Tommaso Pisanti.","year":"1993","isbn":["9788879833172"],"title":"Aforismi sabbia e spuma","oclcnum":"69935068"]}]}

这是我到目前为止的代码:

Dim oJSON          As New JSON
Dim oJSONParsed    As Object

Set oJSONParsed = oJSON.parse(stJsonResponse)

For Each keyName In oJSONParsed.keys
    Select Case keyName
        Case "stat":
            Select Case oJSONParsed(keyName)
                Case "ok":
                    MsgBox "stat OK"
                Case "unknownId":
                    MsgBox "the request identifier looks like a valid ISBN number and unknown to xISBN service"
                Case "invalidId":
                    MsgBox "the request identifier is not a valid ISBN number"
                Case Else
                    'Case "unknownField": 'the request field is not supported
                    'Case "unknownFormat": 'the request format is not supported
                    'Case "unknownLibrary": 'the request library is not supported
                    'Case "unknownMethod": 'the request method is not supported
                    'Case "overlimit": 'the request is throttled, only header is returned
                    'Case "invalidAffiliateId": 'invalid affiliate id
                    'Case "invalidHash": 'invalid hash (subscription only)
                    'Case "invalidToken": 'invalid access token (subscription only)
                    MsgBox "Errore irreversiblie, Case interno su 'stat'"
            End Select
        Case "list":
            'Here I am stuck, I tried several options but I do not know how to proceed
            'Here latest attempt
            Dim temp As String
            temp = ""
            Dim colJSONArray   As Collection
            Set colJSONArray = oJSONParsed.Item("list")
            For Each key In colJSONArray
                '-------> How do I get the values here? <-------
                temp = temp + "Key: " + key + " Value: " + colJSONArray.Item("key") + vbNewLine
            Next
            MsgBox temp
        Case Else
            MsgBox "Errore irreversiblie"
    End Select
Next

代码colJSONArray.Item("key")给了我错误Invalid procedure call or argument
代码print colJSONArray.Count给了我1
任何帮助表示赞赏。

编辑:愚蠢的我......不能在“”中写键!
'colJSONArray.Item(1)' 工作并给了我一个字典......我会从这里移动。

4

1 回答 1

0

如果 colJSONArray.Item("key") 是集合,您需要获取此集合的第一个元素。

...
dim tmp
For Each key In colJSONArray
     tmp = colJSONArray.Item("key")
     temp = temp + "Key: " + key + " Value: " + tmp(Lbound(tmp)) + vbNewLine
next key
....
于 2013-09-07T08:03:31.733 回答