解析大量数据 (5Mb) 的速度更快:eval 还是 json?

发布于 2024-08-28 01:30:02 字数 173 浏览 4 评论 0 原文

我想通过ajax获取数据对象的集合并将它们解析为JS数据。

目前我有2个选择: - 服务器返回有效的 JavaScript 代码,然后我对其进行评估。 - 服务器返回 JSON 对象,然后我评估 json 对象

Firefox 中最快的是什么? (我只关心“解析”性能,而不关心服务器或数据传输)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事与诗 2024-09-04 01:30:02

看看 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.

微凉徒眸意 2024-09-04 01:30:02

在 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))()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文