最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSON2 vs. jquery-json - Stack Overflow

programmeradmin0浏览0评论

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 (/)? Given that a web application is using jQuery to begin with.

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.

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.

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.

Share Improve this question edited Jun 24, 2018 at 21:35 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Oct 20, 2010 at 15:39 DimskiyDimskiy 5,30113 gold badges49 silver badges69 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 16

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.

They are both a handful of functions that do just about the same thing.

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

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

As a thought experiment, let's imagine that every browser had a native JSON api implementation. Would you still use jquery-json?

If so, then use the jquery plug-in.

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)?

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"

Most modern browsers have native JSON build in, jQuery defaults to those functions when using e.g. $.getJSON() or $.parseJSON().

So if you are using jQuery, you don't need any plugin/library for JSON.

发布评论

评论列表(0)

  1. 暂无评论