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

asp如何解析json字符串并转化为asp对象,第1张

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

本文由PHP中文网提供,

文章地址:http://www.php.cn/csharp-article-377133.html

学编程就来PHP中文网 www.php.cn

以上就是asp如何解析json字符串并转化为asp对象的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/685671.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存