jQuery.parseJSON('{"name":"John"}') converts string representation to object but i wnat the reverse. Object is to be converted to JSON string i got a link http://www.devcurry.com/2010/03/convert-javascript-object-to-json.html but it need to have json2.js do jQuery have a native methode to do this?
+1
A:
jQuery does only make some regexp checking before calling the native browser method window.JSON.parse()
. If that is not available, it uses eval()
or more exactly new Function()
to create a Javascript object.
The opposite of JSON.parse()
is JSON.stringify()
which kind of "deserializes" a Javascript object into a string. jQuery does not have an own functionality for that, you have to use the browser build-in version or json2.js
from http://www.json.org
JSON.stringify()
is available in all major browsers, anyway to be compatible with older browsers you still need that fallback.
jAndy
2010-10-11 07:35:58
A:
Hello,
you can write your own toString() function easily.
To loop into a JSON Object you can use :
w = {'a': 'b', 'c': 'd'}
$.each(w, function(key, value) { console.log(key + ": " + value); })
Arnaud F.
2010-10-11 07:46:22