如何将JavaScript对象编码为JSON?(How do I encode a JavaScript object as JSON?)

编程入门 行业动态 更新时间:2024-10-16 00:25:24
如何将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);

更多推荐

本文发布于:2023-08-04 05:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   对象   JavaScript   object   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!