test.asp文件:
<script language="JScript" runat="Server" title="js 也是可以當(dāng)服務(wù)器端腳本的,讓asp調(diào)用">
function StrToArray(s){ //將json字符串轉(zhuǎn)為asp中的詞典數(shù)組Dictionary
var dic = Server.CreateObject("Scripting.Dictionary")
var a=eval("(" + s+")");
for(var key in a){
dic.Add(key, getDic(a[key]));
}
return dic
}
function getDic(ite){
if(typeof(ite)=="object"){
var obj = Server.CreateObject("Scripting.Dictionary")
for(var x in ite){
if(typeof(ite[x])=="object"){
obj.Add(x,getDic(ite[x]));//進(jìn)入循環(huán)
}else{
obj.Add(x,ite[x])
}
}
return obj;
}else{
return ite;
}
}
</script>
<%
‘調(diào)用方式:
set myjson=StrToArray("[{""x"":5},{""x"":9}]")
For Each key In myjson
's = s &myjson(key)("x")& VbCrLf
For Each key1 In myjson(key)
s = s &key1& VbCrLf
next
Next
'response.Write(s)
'response.End()
set myjson=StrToArray("[{""x"":5},{""x"":9}]")
keys=myjson.Keys
For i=0 To myjson.Count-1
s = s &myjson(keys(i))("x")& VbCrLf
next
response.write(s)
response.End()
%>