$.fn.serializeJson = function() {
var serializeObj = {};
var array = this.serializeArray();
$(array).each(
function() {
if (serializeObj[this.name]) {
if ($.isArray(serializeObj[this.name])) {
serializeObj[this.name].push(this.value);
} else {
serializeObj[this.name] = [serializeObj[this.name], this.value ];
}
} else {
serializeObj[this.name] = this.value;
}
}
);
return serializeObj;
};
例: var formSerialize = $('#userInfoForm').serialize();