Reputation:
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
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