简体   繁体   中英

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!

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

Have you looked at the YUI JSON utility ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM