VB6下简易的JSON解析器

  如题,VB6.0 下解析Json,用大佬的解析器(https://blog.csdn.net/bakw/article/details/51035338) 解析后返回值为[object Object]。

  估计是内容可能跟示例的不一样,我要解析的 strJson 是:

{
        "info": [
{ "name": "one", "sex": "two", "age": "three"   },
       {
                "name": "one1",
                "sex": "two1",
                "age": "three1"
          },...
      ]
        "code": 0,
        "msg": "true"
}

  对其进行调整后解决,如下代码。

  调用方式不变:

    取"code":JSONParse("code", strJson) :返回 "one";

    当需要取List中的记录时,请自行拆分下面方法增加可用性;

    判断是否存在第n个list记录:JSONParse("info[n-1]", strJson) :存在返回 "[object Object]" / 不存在返回 "";

    取第2个List中的"name":JSONParse("info[1].name", strJson) :返回 "one1"。

 1 Public Function JSONParse(ByVal JSONPath As String, ByVal JSONString As String) As Variant
 2     On Error GoTo ErrH
 3     Dim JSON As Object
 4     Set JSON = CreateObject("MSScriptControl.ScriptControl")
 5     JSON.Language = "JScript"
 6     JSON.AddCode "var Json = " & JSONString & ";"
 7     JSONParse = JSON.Eval("Json." & JSONPath)
 8     Set JSON = Nothing
 9     Exit Function
10 ErrH:
11     Debug.Print Err.Description
12     Err.Clear
13 End Function