连续复制
一键复制
一键打包

json.stringify() 数组空

var teacher_info = new Array("12","erin","女","12-02","中国");
var data1 = new Array("wage_no","name","sex","birthday","nation");
var data_arr1 = []; 
for (var i=0;i<5;i++){
data_arr1[data1[i]] = teacher_info[i];
}
data_arr1 = JSON.stringify(data_arr1);
console.log(data_arr1);

解决方案是 data_arr1={} 初始化 data_arr1为object

var teacher_info = new Array("12","erin","女","12-02","中国");
 
var data1 = new Array("wage_no","name","sex","birthday","nation");
 
var data_arr1 = {};
 
for (var i=0;i<5;i++){
data_arr1[data1[i]] = teacher_info[i];
}
 
data_arr1 = JSON.stringify(data_arr1);
 
console.log(data_arr1);
这样既可解决使用JSON.stringify转 json,