这个是想要结果
data{
info: { sex: 12, name: "张珊", address: "广东河源" }, obj: [ { sex: 12, name: "张珊", address: "广东河源" },{ sex: 11, name: "李四", address: "广东广州" } ], array: [255,22,22]
}
html的格式可以是这样子的
最好能无限嵌套的那种。
读取每一项表单项,然后去构造一个json呀,然后这种功能如果常用的话,自己封装成一个函数,可以根据name属性的格式自动构造
serializeArray
function getFormJson(form) {
var o = {};
var a = $(form).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
$json = getFormJson('#test')//再自己处理下