Js 数组转JSON格式

var arrays=new Array();
	//JSON.stringify() 不能转下标非1,2,3这种数字的数组,
	//所以采用新建对象的方式添加数据
	var products={};
	products['productid']='32';
	products['name']='手机';
	arrays.push(products);

	var products2={};
	products2['productid']='33';
	products2['name']='电脑';
	arrays.push(products2);
	
var json_arrays = JSON.stringify(arrays);
console.log(json_arrays);

Js 数组转JSON格式_第1张图片

你可能感兴趣的:(前端,js,json)