Last active
August 6, 2018 09:20
-
-
Save tsukanov-as/ef91ea05cdeb074be5bf600cac8aa345 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Parse(Src, Pos = 1) | |
List = New Array; | |
Pos = Pos + 1; Chr = Mid(Src, Pos, 1); | |
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf; | |
Beg = Pos; | |
While Chr <> "" Do | |
If Chr = "{" Then | |
List.Add(Parse(Src, Pos)); | |
Pos = Pos + 1; Chr = Mid(Src, Pos, 1); | |
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf; | |
Beg = Pos; | |
ElsIf Chr = "," Then | |
If Beg < Pos Then | |
List.Add(Mid(Src, Beg, Pos - Beg)); | |
EndIf; | |
Pos = Pos + 1; Chr = Mid(Src, Pos, 1); | |
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf; | |
Beg = Pos; | |
ElsIf Chr = "}" Then | |
If Beg < Pos Then | |
List.Add(Mid(Src, Beg, Pos - Beg)); | |
EndIf; | |
Break; | |
ElsIf Chr = """" Then | |
While Chr = """" Do | |
Pos = Pos + 1; While Mid(Src, Pos, 1) <> """" Do Pos = Pos + 1; EndDo; | |
Pos = Pos + 1; Chr = Mid(Src, Pos, 1); | |
EndDo; | |
Else | |
Pos = Pos + 1; Chr = Mid(Src, Pos, 1); | |
EndIf; | |
EndDo; | |
Return List; | |
EndFunction // Parse() | |
res = Parse(src); | |
JSONWriter = New JSONWriter; | |
JSONWriter.SetString(New JSONWriterSettings(, Chars.Tab)); | |
WriteJSON(JSONWriter, res); | |
Result.SetText(JSONWriter.Close()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment