{"ecode":0,"exp":4,"limit":0,"pkg":[{"id":1,"name":"元宝","num":1000,"type":39}],"ref_limit":0,"ret":0,"wish_num":1,"wish_t":1499612867}
函数过程
Public Function Json(ByVal JSONPath As String, ByVal JSONString As String) As Variant
On Error Resume Next
Dim JS As Object
If JSONString = "" Then Exit Function
Set JS = CreateObject("MSScriptControl.ScriptControl")
JS.Language = "JScript"
Json = JS.Eval("JSON=" & JSONString & ";JSON." & JSONPath & ";")
Set JS = Nothing
End Function
调用:
1、直接取值
ecode=Json("ecode", JsonString)
2、数组长度获取
pkgCount=Json("pkg.length", JsonString)
3、数组内取值
cName=Json("pkg[0].name",JsonString)