json 拼二维json数组
js声明数组 以及向数组中添加as移除json数据 JavaScript声明JSON数组的方法: //部分条件,在数据渲上数据要求是数组格式而非json数组格式,取arrayJson.dataList var arrayJson = {'dataList':[]}; 1 2 向数组中添加json串 arrayJson.dataList.push({'name':'dataName'}); 1 移除所有数组中数据 arrayJson.dataList.splice(0,arrayJson.dataList.length); 1 一下举栗声明json数组串较为复杂并且灵活的格式。 [ { "dateMonth":"05", "hopeMoney":"12000", "data":[ { "brickId":"1", "brickYear":"2017-05-15", "brickWeek":"星期二", "brckInfo":[ { "bringMoneyOrExpenditure":"5000", "brickClass":"工资", "brickIcon":"ion-ios-star-outline" }, { "bringMoneyOrExpenditure":"-2000", "brickClass":"其他", "brickIcon":"ion-ios-star-outline" } ] }, { "brickId":"1", "brickYear":"2017-05-02", "brickWeek":"星期六", "brckInfo":[ { "bringMoneyOrExpenditure":"10000", "brickClass":"工资", "brickIcon":"ion-ios-star-outline" } ] } ] }, { "dateMonth":"04", "hopeMoney":"12000", "data":[ { "brickId":"1", "brickYear":"2017-04-15", "brickWeek":"星期一", "brckInfo":[ { "bringMoneyOrExpenditure":"5000", "brickClass":"工资", "brickIcon":"ion-ios-star-outline" } ] } ] } ]
//我的应用
----注意:引号一定是双引号------想要这种格式
{"userId":3,"productList":[{"productId":1157,"quantity":3},{"productId":1158,"quantity":1}]}
var productList_array = {"userId":member_uid,"productList":[]};
$('.main_div').each(function(){
product_id = $(this).data('id');
product_num = parseInt($(this).data('num'));
productList_array.productList.push({"productId":product_id,"quantity":product_num});
});
console.log(productList_array);
productList_array_jsonstr = JSON.stringify(productList_array);
console.log(productList_array_jsonstr);
return false;
相信坚持的力量,日复一日的习惯.