这次给大家带来asp处理json数据步骤详解,asp处理json数据的注意事项有哪些,下面就是实战案例,一起来看一下。
asp也能处理json数据?呵呵,刚才在pjblog论坛上看到一个兄弟写的文章,没有测试,不过理论上一定是可以的~ 太晚了,不测试了。
以前处理json太麻烦了,输出还好说,循环一下就可以了,解析真的很头疼。所以遇到 这种问题api问题,一般都是xml处理,不太喜欢,很麻烦。
<%
dim sc4json
sub initscriptcontrol
set sc4json = server.createobject("msscriptcontrol.scriptcontrol")
sc4json.language = "javascript"
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, email:[""ycplxl1314@163.com"",""ycplxl1314@gmail.com""], family:{parents:[""父亲"",""母亲""],tostring:function(){return ""家庭成员"";}}}"
dim objtest
call initscriptcontrol
set objtest = getjsonobject(strtest)
%>
<%=objtest.name%>的邮件地址是< %=sc4json.eval("jsonobject.email[0]")%><br />共有邮件地址< %=objtest.email.length%>个<br />
<%
dim father
getjsarrayitem father, objtest.family.parents, 0
response.write father
%>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
php操作json方法大全
json对象和字符串相互转换步骤详解
以上就是asp处理json数据步骤详解的详细内容。