关于JSON的好处就不说了,反正我是喜欢上它了,也开始在自己的项目中使用JSON,前两天刚到官网下载了最新的json.js文件,结果我的页面一打开就报错:too much recursion!在IE和FF中都是如此,刚开始以为是自己的代码写错了,后来仔细看看才发现应该是json.js这个文件有问题,于是照例Google,找到不少资料,不少开发者在使用最新版的json.js文件时都出现了这个问题。
I started off by using the JSON js code, however
this
code is unusable
for
1
major reason
-
it adds a method to array
'
s/objects, resulting in the fact that foreach() always returns an additional member. (breaking almost all the existing javascript code!) - I also ran into problems with recursion in firefox (but I think thats due to me forgetting to add the String.prototype method.)
JSON扩展了Javascript的基本对象,提供了toJSONString()方法,而JQuery也扩展了基本对象,提供了一些方法,有可能是这些方法之间存在冲突,无意中发现有个开发者提到他在用旧版的json.js时并没有碰到这种情况,只是在更新了版本后才出来这种问题的,所以我将json.js替换成比较旧点的版本,结果那个烦人的too many recursion再没出现了。
思考:国内用JSON和JQuery的人也不少了,还有不少实例教我们怎么用这个toJSONString()方法的,可为什么就没有人提到这个问题呢?难道这些实例都只是一个简单的翻译,就没有人自己去实践过?不解。
附:旧版JSON的下载地址如下
Site:
http://web.archive.org/web/20060208035938/http://www.crockford.com/JSON/js.html
JS:
http://web.archive.org/web/20060208035938/http://www.crockford.com/JSON/json.js
本文探讨了新版JSON.js文件导致的toomuchrecursion错误,并分析了其与JQuery之间的潜在冲突原因。通过回退到旧版JSON.js成功解决了这一问题。
428





