微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp如何解析json字符串并转化为asp对象

本文介绍如何使用asp解析json字符串,大家都知道asp对json的处理没有PHP那么简单,也没有键值对数组,这可能也是它最终被PHP取代的直接原因。

下面代码经本人测试可用,

代码如下:

Dim scriptCtrl
Function parseJSON(str)
    If Not IsObject(scriptCtrl) Then
        Set scriptCtrl = Server.CreateObject(MSScriptControl.ScriptControl)
        scriptCtrl.Language = JScript
        scriptCtrl.AddCode Array.prototype.get = function(x) { return this[x]; }; var result = null;
    End If
    scriptCtrl.ExecuteStatement result =  & str & ;
    Set parseJSON = scriptCtrl.CodeObject.result
End Function
Dim json
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
Set scriptCtrl = nothing

本文由编程之家提供,

文章地址:http://www.jb51.cc/csharp-article-377133.html

学编程就来编程之家 www.jb51.cc

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐