我正在尝试生成如下的JSON对象,
{"project":{"name":"test name","description":"test description","identifier":"testid",{"custom_fields":[{"value":"2015-12-01","id":4},{"statr":"2015-12-31,"id":5}]},stack":"Java","enabled_module_names":["issue_tracking","time_tracking"],"tracker_ids":["1","2","3"]}}
当前代码生成除下面的这部分以外的所
{"custom_fields":[{"value":"2015-12-01","id":4},{"value":"2015-12-31,"id":5}]}
单词值不会改变,也应该将输入值作为日期格式,id也是常量.
$(document).ready(function(){
$.fn.serializeObject = function()
{
var o = {};
var a = this.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 {"project":o};
};
$(function() {
$('form').submit(function() {
$('#result').text(JSON.stringify($('form').serializeObject()));
return false;
});
});
在所有其他输入中,此代码捕获输入的名称和输入的值.我试图得到上面提到的JSON对象,是否有可能.请指教.