jQuery JSON
For those of you who like jQuery but cannot find any sensible way of interacting with JSON (Java Object Notation), here is a solution for you.

I come up with this solution while developing several GNUCITIZEN application, including the latest XSSDB and Backframe.
http://www.gnucitizen.org/blog/jquery-json/jquery.json.js
In order to call JSON you have to do the following:
$.json('http://path/to/json?callback={callback}', function yourFunction () {
[your code here]
});
As you can see, everything is very jQuery like so you shouldn’t have any problems.
Comments
http://docs.jquery.com/Ajax#.2.....llback_.29
?
.mario, the getJSON function returns XMLHttpRequest object which is unsuitable when you want to perform cross-domain JSON communication. This is the reason why I needed to write this module.
Ah - I see - i commented pretty late yesterday evening and oversaw the JSOD-JSON aspect (JS on demand)
:)
i don’t follow under what conditions yourFunction() is executed. perhaps after the given callback is run? could you provide a less brief usage example? :0)
should one clean up in the callback and remove the script object from head?
$(”head script:last-child”).remove();
pierre,
the function is executed when JSON returns and evaluates withing the browser. As for the script object, we can do that but I found that sometimes Firefox is too picky and ends up throwing errors… I don’t know why.
FYI, since jQuery 1.2 getJSON can do cross domain communications.
http://docs.jquery.com/Release.....g_JSONP.29
What I find is really lacking in the jQuery framework is methods to manipulate JSON itself. I would like to be able to do things like this:
Even the getJSON methond in jQuery use a simple eval to parse the JSON.. It might sound trivial, but imho it’s not the *best* solution.
http://jollytoad.googlepages.com/json.js
That’s what I’m talking about !