解析大量数据 (5Mb) 的速度更快:eval 还是 json?
我想通过ajax获取数据对象的集合并将它们解析为JS数据。
目前我有2个选择: - 服务器返回有效的 JavaScript 代码,然后我对其进行评估。 - 服务器返回 JSON 对象,然后我评估 json 对象
Firefox 中最快的是什么? (我只关心“解析”性能,而不关心服务器或数据传输)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 VinylFox 在测试 JSON 解码时得出的结果野生的。本机函数在所有浏览器中表现最佳。
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.
在 Firefox 3.5+ 中,有一个原生 json 解析函数
window.JSON.parse
- 这可能是最快的。在较旧的浏览器中,您可能会更好地使用(new Function("return "+json))()
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))()