asp/
使用MS
MS
MS
复制代码 代码如下:
<
Dim sc4Json
Sub Init
Set sc4Json = CreateObject("MS
sc4Json.Language = "
sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"
End Sub
Function getJSONObject(strJSON)
sc4Json.AddCode "var jsonObject = " & strJSON
Set getJSONObject = sc4Json.CodeObject.jsonObject
End Function
Sub getJSArrayItem(objDest,objJSArray,index)
On Error Resume Next
sc4Json.Run "getJSArray",objJSArray, index
Set objDest = sc4Json.CodeObject.itemTemp
If Err.number=0 Then Exit Sub
objDest = sc4Json.CodeObject.itemTemp
End Sub
Dim strTest
strTest = "{name:""alonely"", age:24,hello:function(){return '你好!';}, email:[""ycplxl1314@163.com"",""ycplxl1314@gmail.com""], family:{parents:[""父亲"",""母亲""],toString:function(){return ""家庭成员"";}}}"
Dim objTest
Call Init
Set objTest = getJSONObject(strTest)'创建JSON对象
'对象属性操作
msgbox objTest.name&"-"&objTest.age
'数组操作
getJSArrayItem email,objTest.email,0
msgbox email
'执行方法
msgbox objTest.hello()
msgbox objTest.family.toString()
</
用
复制代码 代码如下:
<
Array.prototype.get = function(x) { return this[x]; };
function parseJSON(strJSON) { return eval("(" + strJSON + ")"); }
</
<
Dim json, obj
json = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}"
Set obj = parseJSON(json)