百度首页 | 百度空间
 
查看文章
 
Google JSON库。
2008-05-06 21:07
129 parse: function (text) {
130 try {
131 return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
132 text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
133 eval('(' + text + ')');
134 } catch (e) {
135 return false;
136 }
137 }

这两个正则不知何意:(

类别:默认分类 | 添加到搜藏 | 浏览() | 评论 (2)
 
最近读者:
 
网友评论:
1
2008-05-07 12:53
/"(\\.|[^"\\])*"/,这个字符串写得好巧妙,试试去……
 
2
2008-05-12 10:34
确保JSON的格式完全遵循JSON规范,而不只是js中的key-value object
moo的一段,当指明secure参数为true时的处理:
decode: function(string, secure){
if ($type(string) != 'string' || !string.length) return null;
if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null;
return eval('(' + string + ')');
}
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu