简体   繁体   中英

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. 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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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