JSON 到 Prototype 中的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/346793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON to string in Prototype
提问by Greg
The people on this website seem to know everything so I figured I would ask this just in case:
这个网站上的人似乎什么都知道,所以我想我会问这个以防万一:
Is there a method/function in prototype that converts a JSON object to a string that you can store in a cookie?
原型中是否有将 JSON 对象转换为可以存储在 cookie 中的字符串的方法/函数?
If not,..i'll just use another external library.
如果没有,..我将使用另一个外部库。
Thanks, Andrww
谢谢,安德鲁
回答by Greg
Sure there is: Prototype JSON
当然有:原型 JSON
var data = {name: 'Violet', occupation: 'character', age: 25 };
var myString = Object.toJSON(data);
// myString = '{"name": "Violet", "occupation": "character", "age": 25}'
Then shove myString into your cookie
然后将 myString 推入您的 cookie
回答by P Arrayah
Assuming you're speaking of Prototype JavaScript framework, why not just use JavaScript's own JSON functionality? JSON does after all stand for JavaScript Object Notation.
假设您说的是Prototype JavaScript framework,为什么不直接使用 JavaScript 自己的 JSON 功能呢?毕竟 JSON 代表 JavaScript Object Notation。

