When you serialise a form using jQuery.serialize(), the method will serialise the form fields and its values so you can submit to the server. Is there a method/function that would do the same with a javascript object instead of a form?
Asked
Active
Viewed 4,652 times
3
-
http://stackoverflow.com/questions/6487699/best-way-to-serialize-unserialize-objects-in-javascript – Jan 01 '14 at 15:35
2 Answers
4
Check out JSON.stringify
.
JSON.stringify({x: 5, y: 6}); // '{"x":5,"y":6}' or '{"y":6,"x":5}'

Dan Abramov
- 264,556
- 84
- 409
- 511
2
You're looking for the jQuery.param
function.

Bergi
- 630,263
- 148
- 957
- 1,375
-
It is jQuery.param() used with decodeURIComponent so the end code would be: `var myvar = decodeURIComponent($.param(myObj))` – WagnerMatosUK Jan 02 '14 at 13:30
-
@WagnerMatosUK: That depends on how you send it to the server, of course :-) – Bergi Jan 02 '14 at 13:42