I'm a Javascript newbie so bear with me. How can I serialise an object to JSON in Javascript? Is there a common external library I can use? I'm aware of jquery.getJSON(...)
but this doesn't seem to quite do what I want, which is to simply get a string containing the JSON for an object in a piece of Javascript.
views:
2431answers:
3
+3
A:
Are you looking for something like the JSON.stringify()? it is what i use for my WCF calls.
Mike_G
2009-02-17 20:16:50
That's what we use where I work.
R. Bemrose
2009-02-17 20:17:29
Perfect, thanks.
Andy
2009-02-17 20:20:17
And it has the added advantage of loking for native JSON implementations (such as that in upcoming ie8 and firefox 3.1), and not overriding them :D
olliej
2009-02-17 21:20:41
A:
Download http://www.JSON.org/json2.js
, include it and do
json_data = JSON.stringify(obj);
Johannes Weiß
2009-02-17 20:18:54
A:
The thing is, http://www.JSON.org/json2.js doesn't serialize an object within an object, or is it a way to do it?
tymonn
2010-08-20 11:16:15