I'm looking for the most up-to-date way to serialize an array of data in Javascript (w/ or w/o jQuery). Using the latest version of the Chrome browser (June 2013).
Simple associative array, PHP using serialize().
array('product_id' => "145549", "field" => "price")
-- serializes to --
a:2:{s:10:"product_id";s:6:"145549";s:5:"field";s:5:"price";}
If there's no easy way to produce the same serialized string using Javascript, is there an equivalent to PHP's json_encode()?
1 Answer 1
To elaborate on what Musa said in a comment. Most modern browsers supply a JSON object. You can use object detection to see if it is available. No jQuery required even if the browser does not have it you can supply it yourself, here.
Native support: SO Thread, even has some nice code examples.
Comments
Explore related questions
See similar questions with these tags.
phpjs, you can use all php kind of function in javascript.