1 Dim buf, str As String
2 With CreateObject("Scripting.FileSystemObject")
3 With .GetFile("D:\XXX\ex.json").OpenAsTextStream
4 buf = .ReadAll
5 .Close
6 End With
7 End With
8 buf = Replace(buf, "[", "")
9 buf = Replace(buf, "]", "")
10 Dim Json: Set Json = JsonConverter.ParseJson(buf)
11 MsgBox Json("AA")
1Sub test()
23 Dim fso As Object
4 Dim json As Object
5 Dim jsonText As String
6 Dim jsonParse As Object
7 Dim i As Variant
8 Dim j As Variant
9 Dim k As Variant
1011 Set fso = CreateObject("Scripting.FileSystemObject")
12 Set json = fso.OpenTextFile("C:\Users\test.json", 1)
13 jsonText = json.ReadAll
14 json.Close
1516 Set jsonParse = JsonConverter.ParseJson(jsonText)
1718 For Each i In jsonParse
19 For Each j In i
20 Debug.Print j
21 If VarType(i(j)) = 9 Then
22 For Each k In i(j)
23 Debug.Print k
24 If VarType(i(j)(k)) = 9 Then
25 For Each m In i(j)(k)
26 Debug.Print m
27 Debug.Print i(j)(k)(m)
28 Next m
29 Else
30 Debug.Print i(j)(k)
31 End If
32 Next k
33 Else
34 Debug.Print i(j)
35 End If
36 Next
37 Next i
3839End Sub
40
1Option Explicit
23Sub test()
45 Dim buf As String
6 With CreateObject("ADODB.Stream")
7 .Charset = "UTF-8"
8 .Open
9 .LoadFromFile "./test.json"
10 buf = .ReadText
11 .Close
12 End With
1314 Dim obj As Object
15 Dim json As Object
16 Dim json2 As Object
17 Dim json3 As Object
18 Dim json4 As Object
19 Dim i As Variant
20 Dim j As Variant
21 Dim k As Variant
2223 Set obj = CreateObject("ScriptControl")
24 obj.Language = "JScript"
25 obj.AddCode "function jsonParse(s){ return eval('('+s+')');}"
2627 Set json = obj.codeobject.jsonParse(buf)
28 Set json2 = CallByName(json, 0, VbGet)
2930 Dim js As Object
31 Dim keys As Object
32 Dim keys2 As Object
33 Dim keys3 As Object
3435 Set js = CreateObject("ScriptControl")
36 js.Language = "JScript"
37 js.AddCode "function getKeys(h) { var keys=[]; for(var k in h){keys.push(k);} return keys; };"
3839 Set keys = js.codeobject.getKeys(json2)
40 For Each i In keys
41 Debug.Print i
42 If Not CallByName(json2, i, VbGet) = "[object Object]" Then
43 Debug.Print CallByName(json2, i, VbGet)
44 Else
45 Set keys2 = js.codeobject.getKeys(CallByName(json2, i, VbGet))
46 For Each j In keys2
47 If Not CallByName(json2, i, VbGet) = "[object Object]" Then
48 Debug.Print json3
49 Else
50 Set json3 = CallByName(json2, i, VbGet)
51 Debug.Print j
52 If Not CallByName(json3, j, VbGet) = "[object Object]" Then
53 Debug.Print CallByName(json3, j, VbGet)
54 Else
55 Set json4 = CallByName(json3, j, VbGet)
56 Set keys3 = js.codeobject.getKeys(CallByName(json3, j, VbGet))
57 For Each k In keys3
58 Debug.Print k
59 Debug.Print CallByName(json4, k, VbGet)
60 Next
61 End If
62 End If
63 Next
64 End If
65 Next
6667End Sub
6869'AA
70'XXXX1
71'BB
72'B1
73'XXXX2
74'B2
75'DDD
76'XXXX3
77'B3
78'EE1
79'XXXX4
80'EE2
81'XXXX5
82'CC
83'XXXX6
84'DD
85'D1
86'XXXX7
87'EE
88'G1
89'XXXX8
90'G2
91'XXXX9