[英]Generate JSON from a form
I'm looking for the inverse of this question in that I seek a utility that can consume a rendered (view source) HTML page/form and generate the JSON that can represent that form's posting. 我在寻找这个问题的反面,因为我寻找一种实用程序,它可以使用呈现的(查看源代码)HTML页面/表单并生成可以表示该表单发布的JSON。 1
1个
The answer suggested http://www.jsonschema.net is close in format - JSON schema to/from JSON code - I want to paste in an HTML form and see the JSON stubbed out. 答案建议http://www.jsonschema.net的格式接近-与JSON代码之间的JSON模式-我想以HTML形式粘贴并看到JSON存根。
thx 谢谢
Something like this: 像这样:
$fn.serializeForm = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
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;
}
Then call: 然后致电:
$('form').serializeForm();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.