Private Function ExtractElement(ByVal Source As String, ByVal Node As String) As Object
Dim L As String, c1 As String = "", c2 As String = ""
L = Split(Source, """" & Node & """:")(1)
If L.StartsWith("""") Or L.StartsWith("{") Or L.StartsWith("[") Then
c1 = Left(L, 1)
If c1 = """" Then c2 = """"
If c1 = "{" Then c2 = "}"
If c1 = "[" Then c2 = "]"
ExtractElement = Extr(L, c1, c2)
Else
ExtractElement = L.Split(",")(0)
End If
Exit Function
End Function
Private Function Extr(ByVal Str As String, ByVal Sep As String, ByVal ClosingSep As String) As String
Dim Pos1 As Integer, Pos2 As Integer, cnt As Integer = 0
For i = 1 To Len(Str)
If Mid(Str, i, Len(ClosingSep)) = ClosingSep And cnt > 0 Then
cnt = cnt - 1
If cnt = 0 Then Pos2 = i
ElseIf Mid(Str, i, Len(Sep)) = Sep Then
If cnt = 0 Then Pos1 = i
cnt = cnt + 1
End If
If cnt = 0 Then
If Pos2 = 0 Then
Return ""
Else
Return Mid(Str, Pos1 + Len(Sep), Pos2 - Len(Sep) - 1)
End If
End If
Next i
Return ""
End Function
Private Function ExtractArray(ByVal Source As String, ByVal Node As String) As Object
Dim L As String, StartTag As String = "[", ClosingTag As String = "]", Cnt As Long = 0, i As Long, j As Long, j1 As Long
If Not Source.StartsWith(",") Then Source = "," & Source
L = Split(Source, ",""" & Node & """:")(1)
' find closing tag of starttag
For i = 1 To Len(L)
If Mid(L, i, 1) = StartTag Then Cnt += 1
If Mid(L, i, 1) = ClosingTag Then Cnt -= 1
If Cnt = 0 Then
L = Mid(L, 2, i - 2)
Dim r()
ReDim r(0)
' find array members: comma-separated {...},{...},....
For j = 1 To Len(L)
If Mid(L, j, 1) = "{" Then
Cnt = Cnt + 1
If Cnt = 1 Then j1 = j
End If
If Mid(L, j, 1) = "}" Then
Cnt = Cnt - 1
If Cnt = 0 Then
If r(UBound(r, 1)) <> "" Then ReDim Preserve r(UBound(r, 1) + 1)
r(UBound(r, 1)) = Mid(L, j1 + 1, j - j1 - 1)
End If
End If
Next j
Return r
Exit Function
End If
Next i
Return Nothing
End Function
Open in new window