Joseph Howe
Joseph Howe

Reputation:

Is there an alternative way of serializing javascript objects to a json string?

I downloaded the code from json.org to serialize/deserialize javascript objects to/from json and it worked just fine. However, in production, it conflicts with my other javascript code apparently because it uses for in loops. Is there another library that does this? Thanks!

Upvotes: 2

Views: 973

Answers (2)

Eli Courtwright
Eli Courtwright

Reputation: 192921

I use jQuery, specifically with the jQuery-JSON plugin. As you can see from the link, this works like so

var thing = {plugin: 'jquery-json', version: 1.3};
var encoded = $.toJSON(thing);              //'{"plugin": "jquery-json", "version": 1.3}'
var name = $.evalJSON(encoded).plugin;      //"jquery-json"
var version = $.evalJSON(encoded).version;  // 1.3

Upvotes: 2

Cal Jacobson
Cal Jacobson

Reputation: 2407

Have you looked at the YUI JSON utility?

Upvotes: 0

Related Questions