On the parsing and splicing of JSON string, first contact, left a note .... Parsing, is to change the code, stitching is pure, the analysis will not say, the notes are stitched upabout the analysis of the three main parts, one is the first layer of processing, one is the second layer of processing, one is to carry out "," the processing. In fact, to a deeper layer can also, I think, the code has to modify the changes.
Public Function Yiceng (A (), B ()) as String
Dim L as Integer
L = UBound (a)-LBound (a) + 1
Dim Str as String
str = str & vbCrLf & Space (6) & "{"
For i = 0 to L-1
If B (i) = "" Then
str = str & CHR & Space (8) & "" "" "" & A (i) & "" "&": "& VbCrLf & Space (Ten) &" ["
str = str & vbCrLf & Space (Ten) & "],"
Else
str = str & CHR & Space (8) & "" "" "& A (i) &" "" & ":" & "" "& B (i) &" "" & " ,"
End If
Next
str = Chuli (str)
str = str & Space (6) & "},"
Yiceng = Yiceng & Str
End Function
Public Function Erceng (str As String, a (), B ()) As String
Dim L as String
L = UBound (a)-LBound (a) + 1
' Find [location, insert operation
Dim I as Integer
i = INSTR (1, str, "]")
Dim Qstr as String
Dim Hstr as String
QSTR = Mid (str, 1, i-1)
HSTR = Mid (str, i)
Dim InStr as String
ISTR = Yiceng (A (), B ())
Erceng = qstr & ISTR & Hstr
' Erceng = Chuli (Erceng)
End Function
' Get rid of the first comma
Public Function Chuli (str as String) as String
Dim y as Integer
y = InStrRev (str, ",")
QSTR = Mid (str, 1, y-1)
HSTR = Mid (str, y + 1)
Chuli = qstr & Hstr
End Function
Test processing
Private Sub Command2_Click ()
Dim A1 ()
Dim B1 ()
Dim C ()
Dim D ()
Dim A2 ()
Dim B2 ()
Dim A3 ()
Dim B3 ()
C () = Array ("4a", "5a", "6a")
D () = Array ("D", "E", "")
A1 () = Array ("1a", "2a", "3a")
B1 () = Array ("A", "B", "C")
A2 () = Array ("A", "a", "a")
B2 () = Array ("A1", "B1", "C1")
A3 () = Array ("AA", "AA", "AA")
B3 () = Array ("A1", "B1", "C1")
Dim Stri as String
Stri = Yiceng (c (), D ())
Stri = Erceng (Stri, A1 (), B1 ())
Stri = Erceng (Stri, A2 (), B2 ())
Stri = Erceng (Stri, A3 (), B3 ())
Stri = Chuli (stri)
Stri = Chuli (stri)
MsgBox Stri
Text1.Text = Stri
End Sub
Where there is a subdirectory where the location is empty, the last two go back ","
Concatenation of JSON strings