ASP( VBScript ) 解析 JSON

<script language="jscript" runat="server">  

Array.prototype.get = function(x) { return this[x]; };  

function parseJSON(strJSON) { return eval("(" + strJSON + ")"); }  

</script>  

<%  

Dim json, obj  

json = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}"  

Set obj = parseJSON(json)  

  

Response.Write obj.a & "<br />"  

Response.Write obj.b.name & "<br />"  

Response.Write obj.c.length & "<br />"  

Response.Write obj.c.get(0) & "<br />"  

  

Set obj = Nothing  

%>  

 

 

 

<script language="JScript" runat="Server">

function ToObject(json) {
    var o;
    eval("o=" + json);
    return o;
}
</script>
<%
set obj1 = ToObject("{aaa:""aaaa"", bbb: ""bbbb""}")
Response.Write obj1.aaa & "<br />"
%>
复制代码
posted @ 2019-02-23 23:58  阿波罗任先生  阅读(1677)  评论(0编辑  收藏  举报