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


本文摘自PHP中文网,作者PHP中文网,侵删。

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

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

代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

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对象的详细内容!

相关阅读 >>

c#如何实现json与对象之间互相转换功能示例

c#获取字符串长度,一个汉字长度为2

asp.net mvc 对用户输入的字符串做trim处理的方法实例

c#中字符串的一般性和特殊性具体介绍(图文)

.net实现微信js-sdk分享功能代码展示

字符串的结束标志是什么?

asp.net mvc 遇到json循环调用的问题应该怎么解决?

字符串处理函数是什么

在什么语言中字符串以\0标志字符串的结束?

asp.net core project.json文件(5)_实用技巧

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...