問題描述
這可能是一個簡單的問題,我似乎找不到可靠的答案.
This is probably a simple question, which I can't seem to find a solid answer to.
為什么要選擇 JSON2 而不是 jquery-json 插件(http://code.google.com/p/jquery-json/)?假設一個 Web 應用程序開始使用 jQuery.
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 也是如此.我歡迎指向博客、文章和示例的鏈接.但是,我正在尋找一個強有力的可靠答案,說明哪個更好用以及為什么.
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的api和native api完全一樣,而jquery-json是jquery插件(和falling略有不同)回到本機實現).
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).
我會說你的答案取決于你想使用哪個 api,因為無論哪種實現,你都會得到相同的結果(你至少應該這樣做).
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).
作為一個思想實驗,讓我們假設每個瀏覽器都有一個原生 JSON api 實現.你還會使用 jquery-json 嗎?
As a thought experiment, let's imagine that every browser had a native JSON api implementation. Would you still use jquery-json?
如果有,那就用jquery插件吧.
If so, then use the jquery plug-in.
如果不是,那么當原生 api 已經眾所周知(即使它沒有全局實現)時,為什么要將代碼綁定到 jquery-json api?
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)?
如果這對你來說意味著什么,John Resig(jQuery 的創建者)說過 與此同時,請開始將使用 JSON 的應用程序遷移到 Crockford 的 json2.js"
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"
這篇關于JSON2 與 jquery-json的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!