如何修改此代码以获得预期结果。
这是我从这段代码中得到的。
{"name":"abc","identifier":"abc_one","number":"55","description":"This is a description"}
但我想要一个像这样的json对象,
{"project":
{"name":"abc",
"identifier":"abc_one",
"number":"55",
"description":"This is a description"}
}
请查看我目前的代码。它需要被另一个对象调用“项目”来扭曲。
$.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 o;
};
$(function() {
$('form').submit(function() {
$('#result').text(JSON.stringify($('form').serializeObject()));
return false;
});
});
<form action="" method="post">
First Name:<input type="text" name="name" maxlength="12" size="12"/> <br/>
Last Name:<input type="text" name="identifier" maxlength="36" size="12"/> <br/>
number:<input type="number" name="number" maxlength="36" size="12"/> <br/>
<textarea wrap="physical" cols="20" name="description" rows="5">Enter your favorite quote!</textarea><br/>
Select a Level of Education:<br/>
<p><input type="submit" /></p>
</form>
答案 0 :(得分:1)
您需要更改的是
((FirstActivity)activity).setTextofTextView("new text");
要
return o;
在serializeObject函数中。