如何将JavaScript对象编码为JSON?(How do I encode a JavaScript object as JSON?)
有没有一种将JavaScript对象编码为JSON的好方法?
我有一个键值对的列表...其中名称来自复选框,并且该值是true还是false,基于是否选中该框?
var values = {}; $('#checks :checkbox').each(function() { values[this.name]=this.checked; });我想将这些值传递到一个JSON对象中,以便存储到一个cookie中以呈现一个表(列将根据用户检查的内容添加)。
有没有人知道解决方案?
Is there a good way to encode a JavaScript object as JSON?
I have a list of key value pairs...where the name is from a checkbox, and the value is either true or false based on whether the box is checked or not:
var values = {}; $('#checks :checkbox').each(function() { values[this.name]=this.checked; });I want to pass these values into a JSON object so store into a cookie to render a table (Columns will be added according to what the user checks off).
Does anyone know a solution?
最满意答案
我想你可以使用JSON.stringify :
// after your each loop JSON.stringify(values);I think you can use JSON.stringify:
// after your each loop JSON.stringify(values);更多推荐
发布评论