Form form converted to JSON format, support array

Source: Internet
Author: User

$.fn.serializeobject = function () {        var keyvalues = This.serializearray ();        var pattern=/\[(\d+) \]/;        var Filter_keys = [],            Normal_keys = Keyvalues.filter (function (v, i) {                if (~v.name.index Of ('. ') | | ~pattern.test (v.name)) {                    Filter_keys.push (v);  & nbsp                 return false              &NBSP ; }                return true;           }) &NBSP;&NB Sp       var Resultjson = {};        Filter_keys.foreach (function (v, i, ary) {  &nbs P         var v_ary = V.name.split ('. '),                V_last = v_ary.length-1;             var deal = function (obj, j, Array) {    &NBSP ;           var me = arguments.callee,                &NBSP ;   Islast = j = = = V_last? true:false;                if (Islast&&!pattern.test (array[j)) {                    if (typeof obj = = ' array ') {                        return Obj.push (v.value);            &NBSP ;      }else{                     if (Obj[array[j]]) {& nbsp                     obj[array[j]]+= ', ' +v.value| | ';                      }else{          &NBSP ;          OBJ[ARRAY[J]] = V.value | | ';                     }            '             return;                   }&N Bsp              }else if (Islast&&pattern.test (array[j)) {      var name = array[j].substr (0, Array[j].indexof ('));                    var index = Array[j].match (pattern) [1];     if (!obj[name]) {            &NB Sp           Obj[name] = [];                   }& nbsp                   if (obj[name].length<= index) {      &NBS P                return Obj[name].push (v.value| | ");                    }   }          & nbsp     var nextobj;                if (Pattern.test (array[j)) {  &nbs P                 var name = array[j].substr (0, Array[j].indexof (' ['));                    var index = Array[j].match (pattern) [1];      &NBSP ;             if (!obj[name]) {                        Obj[name] = [];                   }    & nbsp               if (obj[name].length<= index) {          &NBS P             nextobj={};              &NBSP         Obj[name].push (nextobj);                    }else{                        nextobj=obj[name][index];                   }               } else {                    if (!obj[array[j]) {      &NBS P                 OBJ[ARRAY[J]] = {};            &NBSP ;      }                    nextobj=obj[array[j]];  & nbsp            }                return Me (Nextobj, J + 1, array);           }            deal (Resultjson, 0, v_ary);   &NBSp    });        Normal_keys.foreach (function (v) {            R Esultjson[v.name] = v.value;       };        return resultjson;   }&N bsp;1. Form input, etc. name is named as follows Book[0].title2. Supports multi-series groups 3. The table singular group subscript must be in order and starting from 0 4. With the same name tag merges multiple name values and splits with ","

Form form converted to JSON format, support array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.