JSON(Javscript Object Notation, JS 物件簡譜)目前非常流行,作為主流的前後端資料傳輸交換格式,任何後端語言都需要能解析!
ASP語言主流語言VBscript中並無現成的解析解決方案,一直以來讓很多開發者比較頭疼!
其實,我們可以借用javascript語言來解析,解析程式碼如下:
Array。prototype。get = function(x) { return this[x]; };
function parseJSON(strJSON) { return eval(“(” + strJSON + “)”); }
具體使用舉例:
<%
Dim json, jsonObj
‘====json字串=====
json = “{aa:”“aaa”“, bb:{ name:”“bb”“, value:”“text”“ }, cc:[”“item0”“, ”“item1”“, ”“item2”“]}”
‘=====設定為物件=====
Set jsonObj = parseJSON(json)
’=====對外輸出=======
Response。Write jsonObj。aa & “
”
Response。Write jsonObj。bb。name & “
”
Response。Write jsonObj。cc。length & “
”
Response。Write jsonObj。cc。get(0) & “
”
Set jsonObj = Nothing
%>