asp操作json对象示例
本示例通过服务器端的JScript作为桥接,实现vbscript通过json字符生成对应的JSON对象。
<script language="JScript" runat="Server"> //注意不同格式的JSON格式的字符串调用不同的方法 function toObject(json) {//JSON对象格式的字符串 eval("var o=" + json); return o; } function toArray(s) {//JSON对象数组格式的字符串 var dic = Server.CreateObject("Scripting.Dictionary") eval("var a=" + json); for (var i = 0; i < a.length; i++) { var obj = Server.CreateObject("Scripting.Dictionary") for (x in a[i]) obj.Add(x, a[i][x]) dic.Add(i, obj); } return dic } </script> <% Response.CharSet="utf-8" Dim json json ="{""px_name"":""第二届"",""px_ksjs"":""2014-03-11"",""px_kcfl"":""培训课程""}" Set json = toObject(json)'JSON格式的字符串,需要调用toObject方法 Response.Write json.px_name & " <br/>" Response.Write json.px_ksjs & " <br/>" Response.Write json.px_kcfl & " <br/>" Set json = Nothing json ="[{'uid':'1','username':'abc','email':'123@163.com'},{'uid':'2','username':'dbc','email':'456@163.com'}]" Set json = toArray(json)'JSON对象数组格式的字符串,需要调用toArray方法 For i=0 To json.Count-1 Response.Write json(i).("uid") & " <br/>" Response.Write json(i)("username") & " <br/>" Response.Write json(i)("email") & " <br/>" Next Set json = Nothing %>
加支付宝好友偷能量挖...
原创文章,转载请注明出处:asp操作json对象示例