javascript JSON2 与 jquery-json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3979649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON2 vs. jquery-json
提问by Dimskiy
This is probably a simple question, which I can't seem to find a solid answer to.
这可能是一个简单的问题,我似乎无法找到可靠的答案。
Why would one choose JSON2 over jquery-json plugin (http://code.google.com/p/jquery-json/)? Given that a web application is using jQuery to begin with.
为什么会选择 JSON2 而不是 jquery-json 插件(http://code.google.com/p/jquery-json/)?鉴于 Web 应用程序一开始就使用 jQuery。
Everyone's writing about how great it is that JSON2 falls back on the native implementation; well, so does jquery-json. I welcome links to blogs, articles and examples. However, I'm looking for a strong solid answer on which one is better to use and why.
每个人都在写关于 JSON2 依靠本机实现的伟大之处;好吧,jquery-json 也是如此。我欢迎指向博客、文章和示例的链接。但是,我正在寻找一个强有力的可靠答案,说明哪个更好用以及为什么。
回答by Brantley Harris
Author of jquery-json here. It really doesn't matter much. I made jquery-json a long time ago when there were no good options, and keep it there because a lot of people like it.
jquery-json 的作者在这里。这真的没有多大关系。很久以前,当没有好的选择时,我制作了 jquery-json,并将其保留在那里,因为很多人喜欢它。
They are both a handful of functions that do just about the same thing.
它们都是一些功能几乎相同的功能。
回答by Ken Browning
An important difference between the two is that JSON2's api is exactly the same as the native api whereas jquery-json is a jquery plugin (which is slightly different than falling back on the native implementation).
两者之间的一个重要区别是 JSON2 的 api 与原生 api 完全相同,而 jquery-json 是一个 jquery 插件(与回退到原生实现略有不同)。
I would say your answer depends on which api you want to use since you'll get the same results with either implementation (you should at least).
我会说你的答案取决于你想使用哪个 api,因为你会得到相同的结果(你应该至少)。
As a thought experiment, let's imagine that every browser had a native JSON api implementation. Would you still use jquery-json?
作为一个思想实验,让我们假设每个浏览器都有一个原生的 JSON api 实现。你还会使用 jquery-json 吗?
If so, then use the jquery plug-in.
如果是这样,那么使用jquery插件。
If not, then why would you tie your code to the jquery-json api when the native api is already well-known (even if its not globally implemented)?
如果不是,那么当原生 api 已经众所周知(即使它没有全局实现)时,为什么要将代码绑定到 jquery-json api?
If it means anything to you, John Resig (the creator of jQuery) has said"In the meantime PLEASE start migrating your JSON-using applications over to Crockford's json2.js"
如果这对您来说意味着什么,John Resig(jQuery 的创建者)曾说过“与此同时,请开始将您使用 JSON 的应用程序迁移到 Crockford 的 json2.js”
回答by saibotd
Most modern browsers have native JSONbuild in, jQuery defaults to those functions when using e.g. $.getJSON()or $.parseJSON().
大多数现代浏览器都内置了原生 JSON,jQuery 默认使用这些函数,例如$.getJSON()或$.parseJSON()。
So if you are using jQuery, you don't need any plugin/library for JSON.
因此,如果您使用 jQuery,则不需要任何 JSON 插件/库。

