form表单序列化成json数据 将空值用空字符串代替(form表单中checkBox数据会用逗号隔开拼接成字符串)

$.fn.notEmptyserializeJson = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
o[this.name] = o[this.name] + ‘,’ + this.value || ”;
} else {
o[this.name] = this.value || ”;
}
});

var $radio = $(‘input[type=radio],input[type=checkbox]’,this);
$.each($radio,function(){
if(!o.hasOwnProperty(this.name)){
o[this.name] = ”;
}
});

return JSON.stringify(o);
};