sometimes we want convert form data to json str
show code:; (function ($) {
$.fn.fromtojson = function () {
var dataArray = $(this).serializeArray();
var jsonobj = {};
//遍历组装成json格式
for (var i = 0; i
var obj = dataArray[i];
//判断键是否已经存在
if (jsonobj[obj.name] != undefined) {
jsonobj[obj.name] = jsonobj[obj.name] + "," + obj.value;
}
else {
jsonobj[obj.name] = obj.value
}
}
//把json对象转换成字符串
var jsonstr = JSON.stringify(jsonobj);
return jsonstr;
}
})(jQuery);
欢迎加群讨论技术,群号:677373950