問(wèn)題描述
這可能是一個(gè)簡(jiǎn)單的問(wèn)題,我似乎找不到可靠的答案.
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/)?假設(shè)一個(gè) Web 應(yīng)用程序開始使用 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.
每個(gè)人都在寫 JSON2 依賴于原生實(shí)現(xiàn)的偉大之處;好吧,jquery-json 也是如此.我歡迎指向博客、文章和示例的鏈接.但是,我正在尋找一個(gè)強(qiáng)有力的可靠答案,說(shuō)明哪個(gè)更好用以及為什么.
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.
推薦答案
兩者的一個(gè)重要區(qū)別是json2的api和native api完全一樣,而jquery-json是jquery插件(和falling略有不同)回到本機(jī)實(shí)現(xiàn)).
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).
我會(huì)說(shuō)你的答案取決于你想使用哪個(gè) api,因?yàn)闊o(wú)論哪種實(shí)現(xiàn),你都會(huì)得到相同的結(jié)果(你至少應(yīng)該這樣做).
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).
作為一個(gè)思想實(shí)驗(yàn),讓我們假設(shè)每個(gè)瀏覽器都有一個(gè)原生 JSON api 實(shí)現(xiàn).你還會(huì)使用 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.
如果不是,那么當(dāng)原生 api 已經(jīng)眾所周知(即使它沒(méi)有全局實(shí)現(xiàn))時(shí),為什么要將代碼綁定到 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)?
如果這對(duì)你來(lái)說(shuō)意味著什么,John Resig(jQuery 的創(chuàng)建者)說(shuō)過(guò) 與此同時(shí),請(qǐng)開始將使用 JSON 的應(yīng)用程序遷移到 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"
這篇關(guān)于JSON2 與 jquery-json的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!