前端之家收集整理的这篇文章主要介绍了
VB6下简易的JSON解析器,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Public Function JSONParse(ByVal JSONPath As String,ByVal JSONString As String) As Variant
Dim JSON As Object
Set JSON = CreateObject("MSScriptControl.ScriptControl")
JSON.Language = "JScript"
JSONParse = JSON.eval("JSON=" & JSONString & ";JSON." & JSONPath & ";")
Set JSON = Nothing
End Function
调用方式,
JSONPath为数据访问路径
JSONString为JSON格式源
数据
如源
数据内容Data为
{
"programmers":[{
"firstName":"Brett",
"lastName":"McLaughlin",
"email":"aaaa"
},{
"firstName":"Jason",
"lastName":"Hunter",
"email":"bbbb"
},{
"firstName":"Elliotte",
"lastName":"Harold",
"email":"cccc"
}],
"authors":[{
"firstName":"Isaac",
"lastName":"Asimov",
"genre":"sciencefiction"
},{
"firstName":"Tad",
"lastName":"Williams",
"genre":"fantasy"
},{
"firstName":"Frank",
"lastName":"Peretti",
"genre":"christianfiction"
}],
"musicians":[{
"firstName":"Eric",
"lastName":"Clapton",
"instrument":"guitar"
},{
"firstName":"Sergei",
"lastName":"Rachmaninoff",
"instrument":"piano"
}]
} ----------------- JSONParse("programmers.length",Data) 3 JSONParse("musicians[1].instrument",Data) piano
原文链接:https://www.f2er.com/vb/257038.html