I also recommend using json2.js for anything more then just a basic key-value json string.
I ran into troubles with the standard jQuery json approach, when implementing a complex system that transfers a lot of json to and from the server. And as Michael Geary mentions: "If you want to *generate* JSON in your JavaScript code (e.g. if your server > expects you to send it JSON data in a POST), JSON.stringify() from json2.js > is the way to do it." > Cam On Tue, Aug 11, 2009 at 3:13 PM, MorningZ <[email protected]> wrote: > > "Speaking of: i recommend AGAINST using getJSON()" > > I'd also recommend against use of $.getJSON for a totally different > reason: > > There is no option to "catch" errors..... > > getJSON: function(url, data, callback) { > return jQuery.get(url, data, callback, "json"); > }, > > so if something happens server side or there is a glitch in the Matrix > that we call the internet, your code would just dead stop, and your > user would be sitting there waiting and waiting and waiting > > > > On Aug 10, 9:54 pm, Miket3 <[email protected]> wrote: > > I'll just add my 2 cents from novice to novice. > > 1. JSON is just a lightweight markup language. Its like HTML, and more > > like XML but just without the weight. And it is easier to read with > > the eyeball. > > JSON uses {} squiggles and : and [] and others to markup the data. > > > > JSON {"CATALOG" : "JCPENNY"} > > XML <CATALOG>JCPENNY</CATALOG> > > > > http://www.json.org/example.html has some good comparisons. > > > > On Aug 10, 6:26 pm, "Michael Geary" <[email protected]> wrote: > > > > > > > From: Joey Derrico > > > > > > > I am a novice at AJAX and JSON (Ok, I am a novice at > > > > > JavaScript.), and > > > > > I am brand new to jQuery. I wanted to use JSON in a project I am > > > > > working on and I read various tutorials on using JSON with jQuery > > > > > however none of them answered some of my questions. The biggest one > > > > > is, does jQuery support JSON or do I need to use another > > > > > JSON library to use JSON with jQuery? > > > > From: Stephan Beal > > > > > > JSON is simply a data format. "Supporting" JSON simply means having: > > > > > > a) a function which can transform JS objects into a > > > > JSON-compliant string. > > > > b) a function which can transform a compliant string into a JS > object. > > > > > > AFAIK, jQuery doesn't have any built-in support for JSON, but > > > > it doesn't have to - it doesn't operate at a level where JSON > > > > would be useful (except for possible selector-style traversal > > > > of a JSON tree). > > > > > > The canonical JSON implementation for JavaScript is Doug > > > > Crockford's json2.js, available here: > > > > > >http://www.json.org/ > > > > > > See JSON.stringify() and JSON.parse(). > > > > > Actually, jQuery does provide quite a bit of built-in JSON support, and > for > > > a large category of apps, it provides all the support you need. > > > > > If you want to make GET or POST requests to a server, get JSON data > back, > > > and use that data in your JavaScript code, you don't need json2.js. > jQuery > > > supports all of that, both for JSON data on your own server or JSONP > data > > > coming from other domains. > > > > > Just use $.getJSON() or $.ajax() with the 'json' or 'jsonp' dataType as > > > needed. > > > > > If you want to *generate* JSON in your JavaScript code (e.g. if your > server > > > expects you to send it JSON data in a POST), JSON.stringify() from > json2.js > > > is the way to do it. > > > > > If you want a "safer" JSON parser instead of the "eval-ing" JSON parser > that > > > jQuery uses, then JSON.parse() from json2.js will give you that. But > for > > > most apps you don't need this (and it's less useful than it might > sound). > > > > > Otherwise, you can just use the JSON support in jQuery. > > > > > -Mike >

