0

に記載されているパーサーを使用しています: Is There a JSON Parser for VB6 / VBA? しかし、ネストされた配列の値を取得する際に問題があります。これが私が持っているJSON文字列です(Webサービスからの応答、検証済みで、有効な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)」が機能し、Dictionary が表示されます... ここから移動します。

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 に答える