js生成json数据

<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>

上一篇:创建以mybatis为基础的web项目(2)mabitis中的一对一关系项目实战


下一篇:Technical analysis of client identification mechanisms