Vb6 parsing json data

vb6 does not support json object, here use js to achieve json parsing

get simple json string value

Dim ScriptObj As Object
Dim JsonStr As String
JsonStr = "{""code"":""0"",""msg"":""SUCCESS""}"

Set ScriptObj = CreateObject("MSScriptControl.ScriptControl")
ScriptObj.Language = "JavaScript"
ScriptObj.AddCode "var Json = " & JsonStr & ";"

MsgBox ScriptObj.eval("Json.code")

traverse json key value pairs Complex json string

Dim ScriptObj As Object
Dim JsonStr, sourceData As String
JsonStr = "{""code"":""0"",""msg"":""SUCCESS"",""data": _
{""AAA"":""111"",""BBB"",""222"",""CCC"",""333"",......}"}"

Set ScriptObj = CreateObject("MSScriptControl.ScriptControl")
ScriptObj.Language = "JavaScript"
ScriptObj.AddCode "var Json = " & JsonStr & ";var result = """";"

'Execute js statement, traverse json object, nestable loop
ScriptObj.ExecuteStatement ("for (var key in Json.data) {result += ""|"" + key + "":"" + Json.data[key];}")

sourceData = ScriptObj.eval("lockinfo")

Dim arrStr() As String
Dim temStr As Variant

arrStr = Split(sourceData, "|")' parsing the stitched string
For Each temStr In arrStr
    If temStr <> Empty Then
Msgbox Split(temStr, ":")(0) & ":" & Split(temStr, ":")(1)
    End If
Next

But the second method has poor performance and limited application scenarios