开发者

What's faster to parse lots of data (5Mb): eval or json?

开发者 https://www.devze.com 2022-12-26 18:58 出处:网络
I want to get, via ajax, a collection of data objects and parse them into 开发者_开发技巧JS data.

I want to get, via ajax, a collection of data objects and parse them into 开发者_开发技巧JS data.

Currently I have 2 choices: - Server returns valid javascript code and then I eval it. - Server returns JSON object and then I eval the json object

What is the fastest of these in Firefox? (I only care about the "parsing" performance, not server or data transfer)


Have a look at the results VinylFox came up with when he tested JSON decoding in the wild. The native functions performed best across all browsers.


In Firefox 3.5+ there is a native json parsing function window.JSON.parse - this would likely be the fastest. In older browsers, you might have better luck with (new Function("return "+json))()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号