VBScript把json字符串解析成json对象的2个方法
前端 / 管理员 发布于 7年前 243
asp/vbscript将json字符解析为json对象的方法,如果asp使用jscript来编写服务器端代码操作json字符串就简单了,vbscript需要MSScriptControl.ScriptControl或者服务器端的jscript来作为中间体才行。
vbscript将json字符解析为json对象的方法一
使用MSScriptControl.ScriptControl组件,请用IE浏览器运行本示例,会有安全提示,需要点击“是”允许创建。
MSScriptControl.ScriptControl组件的用法实例
MSScriptControl.ScriptControl组件属性、方法、事件介绍
<script language="vbscript">Dim sc4JsonSub InitScriptControl Set sc4Json = CreateObject("MSScriptControl.ScriptControl") sc4Json.Language = "JavaScript" sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"End Sub Function getJSONObject(strJSON) sc4Json.AddCode "var jsonObject = " & strJSON Set getJSONObject = sc4Json.CodeObject.jsonObjectEnd Function Sub getJSArrayItem(objDest,objJSArray,index) On Error Resume Next sc4Json.Run "getJSArray",objJSArray, index Set objDest = sc4Json.CodeObject.itemTemp If Err.number=0 Then Exit Sub objDest = sc4Json.CodeObject.itemTempEnd Sub Dim strTeststrTest = "{name:""alonely"", age:24,hello:function(){return '你好!';}, email:[""ycplxl1314@163.com"",""ycplxl1314@gmail.com""], family:{parents:[""父亲"",""母亲""],toString:function(){return ""家庭成员"";}}}"Dim objTestCall InitScriptControl'初始化MSScriptControl.ScriptControl组件Set objTest = getJSONObject(strTest)'创建JSON对象'对象属性操作msgbox objTest.name&"-"&objTest.age'数组操作getJSArrayItem email,objTest.email,0msgbox email'执行方法msgbox objTest.hello()msgbox objTest.family.toString()</script>
vbscript将json字符解析为json对象的方法二
用jscript作为中间体
<script language="javascript">//运行在服务器端时,增加runat="server"属性Array.prototype.get = function(x) { return this[x]; }; function parseJSON(strJSON) { return eval("(" + strJSON + ")"); } </script> <script language="vbscript">Dim json, obj json = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}" Set obj = parseJSON(json) </script>
这篇文章就介绍到这了,需要的朋友可以参考一下。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号