我使用類似下面,這是相當具體到JSON雖然,但很輕,重夾具每次我需要分析新的數據:
Public Sub ReadJson()
Const JsonString As String = "{""valid"":""true"",""isinCode"":null,""lastUpdateTime"":""15-OCT-2012 14:18:56"",""tradedDate"":""15OCT2012"",""data"":[{""change"":""16.75"",""lastPrice"":""5,703.30""}]}"
Dim objJson As Object
Dim objSE As Object
Set objSE = CreateObject("ScriptControl")
With objSE
.Language = "JScript"
.AddCode "function getProp(jsonObj, propertyName) { return jsonObj[propertyName]; } "
.AddCode "function getSubProp(jsonObj, pName, propertyName) { return jsonObj[pName][0][propertyName]; } "
End With
With objSE
Set objJson = .Eval("(" + JsonString + ")")
Debug.Print .Run("getProp", objJson, "valid")
Debug.Print .Run("getProp", objJson, "isinCode")
Debug.Print .Run("getProp", objJson, "lastUpdateTime")
Debug.Print .Run("getProp", objJson, "tradedDate")
Debug.Print .Run("getSubProp", objJson, "data", "change")
Debug.Print .Run("getSubProp", objJson, "data", "lastPrice")
End With
End Sub
來源
2012-10-15 16:48:32
SWa
硬,不知道如何您的JSON庫結構的說VBA中的對象。也許你可以展示相關的代碼。 –