,可以通过以下步骤实现:
Function ParseJSON(jsonString As String) As Dictionary
Dim json As Object
Set json = JsonConverter.ParseJson(jsonString)
Set ParseJSON = json
End Function
Sub Main()
Dim jsonString As String
Dim jsonData As Dictionary
' 假设jsonString是包含JSON数据的字符串
jsonString = "{""name"": ""John"", ""age"": 30, ""city"": ""New York""}"
' 解析JSON数据
Set jsonData = ParseJSON(jsonString)
' 访问JSON数据
Debug.Print "Name: " & jsonData("name")
Debug.Print "Age: " & jsonData("age")
Debug.Print "City: " & jsonData("city")
End Sub
Sub Main()
Dim jsonString As String
Dim jsonData As Dictionary
Dim dataArray() As Variant
Dim i As Integer
' 假设jsonString是包含JSON数组的字符串
jsonString = "[{""name"": ""John"", ""age"": 30, ""city"": ""New York""}, {""name"": ""Jane"", ""age"": 25, ""city"": ""London""}]"
' 解析JSON数据
Set jsonData = ParseJSON(jsonString)
' 初始化数组
ReDim dataArray(1 To jsonData.Count, 1 To 3)
' 将JSON数据存储到数组中
For i = 1 To jsonData.Count
dataArray(i, 1) = jsonData(i)("name")
dataArray(i, 2) = jsonData(i)("age")
dataArray(i, 3) = jsonData(i)("city")
Next i
' 打印数组数据
For i = 1 To jsonData.Count
Debug.Print "Name: " & dataArray(i, 1)
Debug.Print "Age: " & dataArray(i, 2)
Debug.Print "City: " & dataArray(i, 3)
Next i
End Sub
以上代码示例了如何将JSON结果存储到VBA数组中。根据实际情况,可以根据JSON数据的结构和需要进行相应的调整和扩展。
领取专属 10元无门槛券
手把手带您无忧上云