如何用javascript定义对象数组,我要把对象数组转成json传到后台,

2024-11-01 17:27:58
推荐回答(3个)
回答1:

var students = [];
students[students.length] = new Object();
students[students.length] .name = "Lanny";
students[students.length] .age = "25";
students[students.length] .location = "China";
var json = JSON.stringify(students);

var student = new Object();
student.name = "Lanny";
student.age = "25";
student.location = "China";
students = (students || []).push(student);
var json = JSON.stringify(students);

回答2:

var arr = [];
arr[0] = {name: value 。。。};
arr[1] = {name: value 。。。};

回答3:

js是弱类型语言。
你可以自己在页面拼成json格式字符串,然后传到后台啊。
例如“{name:'25',age:'25'}”;