繁体   English   中英

从表单生成JSON

[英]Generate JSON from a form

我在寻找这个问题的反面,因为我寻找一种实用程序,它可以使用呈现的(查看源代码)HTML页面/表单并生成可以表示该表单发布的JSON。 1个

答案建议http://www.jsonschema.net的格式接近-与JSON代码之间的JSON模式-我想以HTML形式粘贴并看到JSON存根。

谢谢

像这样:

$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;
}

然后致电:

$('form').serializeForm();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM