首页 > Web开发 > 详细

jquery json对象转换

时间:2019-11-15 12:54:07      阅读:81      评论:0      收藏:0      [点我收藏+]

jquery json对象转换

<pre>
//json数组转json串
var arr = [1,2,3, { a : 1 } ];
JSON.stringify( arr );

//json字符串转json数组
var jsonStr = ‘[1,2,3,{"a":1}]‘;
JSON.parse( jsonStr );
</pre>

额外小知识:
如果要拼json字符串 以下2种写法 (先拼接json对象 然后再转换成json字符串) 数据和json对象都可以看成 json对象
<pre>
var contact = new Object();
contact["firstname"] = "Jesper";
contact["surname"] = "Aaberg";
console.log(JSON.stringify(contact));

</pre>

<pre>
var sellist = [];
$(‘.sel‘).each(function() {
var sel = $(this).val();
sellist.push(sel);
})
var sellist = JSON.stringify(sellist);
</pre>

 

jquery json对象转换

原文:https://www.cnblogs.com/newmiracle/p/11865573.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!