Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON stringify missing from jQuery 1.4.1?

Apparently jQuery has the ability to decode a given object or string into a JSON object. However, I have a JS object that I need to POST back to the server and I find no utility in jQuery that wraps the JSON.stringify() function. That function is found in Chrome, Safari 4, FF3.6, and IE8 but is not found in earlier browsers. I can use it natively in the browsers that support it, but otherwise am forced to fall back to using Crockford's JSON scripts.

Is there some built-in with jQuery that handles JSON encoding and decoding that takes the place of the Crockford scripts?

like image 818
Geuis Avatar asked Feb 17 '10 00:02

Geuis


2 Answers

You might want to check this out: http://www.json.org/js.html

like image 116
shinkou Avatar answered Sep 21 '22 17:09

shinkou


You can use "Closure Library" (Google) to make a cross browser JSON encoder/decoder.

Just go to http://closure-compiler.appspot.com/

and insert the following into the text field, then hit "Compile":

// ==ClosureCompiler== // @compilation_level ADVANCED_OPTIMIZATIONS // @output_file_name default.js // @use_closure_library true // ==/ClosureCompiler==  goog.require('goog.json'); if (!window['JSON']) window['JSON']={}; if (typeof window['JSON']['stringify'] !== 'function') window['JSON']['stringify']=goog.json.serialize; if (typeof window['JSON']['parse'] !== 'function') window['JSON']['parse']=goog.json.parse; 
like image 36
stewe Avatar answered Sep 22 '22 17:09

stewe