|
|
A colleague of mine was recently searching for a plug-in or script that can convert a JavaScript array to JSON. I asked him to check out JSON.stringify() in the json2.js library, which serializes the JavaScript object into JSON text. Here’s a sample if you do not know about this library:
Note: Make sure that you minify this library and then use the .js directly from your application. For demo purposes I am referring to this .js file directly. In production applications, it is not advisable to do so.
<script type="text/javascript" src="http://www.json.org/json2.js">
</script>
<script type="text/javascript">
var arrCars = new Array("Toyota", "Mercedes", "BMW");
var jsonStr = JSON.stringify(arrCars);
alert(jsonStr);
</script>
'Like' us on our FaceBook page if you find this blog useful. Thanks!
Did you like this post?
|
|
|
||
|
|
|
|
Save on Delicious |
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |





comments
6 Responses to "Convert a JavaScript object to JSON"As a note, JSON.parse is native in modern browsers & json2.js is helpful for older browsers.
You can see @cowboy's blog post for more details http://j.mp/d2d2g9
~/Elijah Manor
Yep! Thanks for adding that comment Elijah. Here's some more info:
http://ejohn.org/blog/the-state-of-json/
What is means of curry. i thing it is a vegetable करी पत्ता
Curry is a spice mixture of widely varying compositions. My site is called devcurry since it is a mixture of ideas, experiments and thoughts for developers to cook ;)
This is a very good site it contains information for both all kind of users.
the returned string isnt json...
Post a Comment