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 %>
更多相关asp 处理json的文章可以继续往下看
如对本文有疑问, 点击进行留言回复!!
asp中Request.ServerVariables的参数集合
网友评论