当前位置: 首页 > 图文教程 > 网络编程 > Javascript > ASP Json Parser修正版

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 ASP Json Parser修正版


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 449 ::
收藏到网摘: n/a

之前因为要用json,在网上,json Generator就不少,但是,parser鲜有后来,在一个老外的启发下,写了一个praser,其实超简单,就是利用了JS的eval来parse,然后,把对象再返回给vbscript代码。 但后来用的时候,发现一个问题,如果json比较单纯,就没什么问题,如果json中含有数组,由于vbs是不可以直接引用js中数组元素的,所以,导致无法访问json对象中的数组元素。试过很多种办法,pop啦,之类的,都不行。再查网上,也无果。
郁闷很久, 转而搜索"vbscript how to access javascript array",竟然给我找到一篇老外的文章。经过调试,发现老外的办法不错。访问不了的原因是没有定义相应的get方法。转而加入他这个get索引器,一试,ok了。
代码如下:
asp json parser
代码
复制代码 代码如下:

<script language="javascript" runat="server">
Array.prototype.get = function(prop)
{
return this[prop];
}
function parseToJson(json_data)
{
eval("var o=" + json_data);
return (o);
}
</script>
"