<script src="~/static/js/jquery.min.js"></script>
<script type="text/javascript">
var list = [];//创建数组
var a1 = {};//创建对象
a1.t = "a";
a1.v = "b,s,g";
var a2 = {};
a2.t = "c";
a2.v = "d,h,e";
list.push(a1);//添加对象
list.push(a2);
var j = JSON.stringify(list);//将对象转换为json
console.log(j);
alert(j);
//将字符串转换为json对象
JSON.parse(‘[{"t":"a","v":"b,s,g"},{"t":"c","v":"d,h,e"}]‘);
</script>
时间: 2024-10-11 21:56:55