JSON到Prototype中的字符串

3 string cookies json prototypejs

这个网站上的人似乎知道一切,所以我想我会问这个以防万一:

原型中是否有方法/函数将JSON对象转换为可以存储在cookie中的字符串?

如果没有,..我将只使用另一个外部库.

谢谢,Andrww

Gre*_*reg 7

当然有:Prototype JSON

var data = {name: 'Violet', occupation: 'character', age: 25 };
var myString = Object.toJSON(data);
// myString = '{"name": "Violet", "occupation": "character", "age": 25}'
Run Code Online (Sandbox Code Playgroud)

然后将myString推入你的cookie