Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert jQuery.serialize() data to JSON object?
    primarykey
    data
    text
    <p>Is there any better solution to convert a form data that is already serialized by jQuery function serialize(), when the form contains multiple input Array fields. I want to be able to convert the form data in to a JSON object to recreate some other informative tables. So tell me a better way to get the serialize string converted as a JSON object.</p> <pre><code>&lt;form id='sampleform'&gt; &lt;input name='MyName' type='text' /&gt; // Raf &lt;!--array input fields below--&gt; &lt;input name='friendname[]' type='text' /&gt; // Bily &lt;input name='fiendemail[]' type='text' /&gt; // bily@someemail.com &lt;!--duplicated fields below to add more friends --&gt; &lt;input name='friendname[]' type='text' /&gt; // Andy &lt;input name='fiendemail[]' type='text' /&gt; // Andy@somwhere.com &lt;input name='friendname[]' type='text' /&gt; // Adam &lt;input name='fiendemail[]' type='text' /&gt; // Adam@herenthere.com &lt;/form&gt; </code></pre> <p>The jquery method applied to get the data</p> <pre><code>var MyForm = $("#sampleform").serialize(); /** result : MyName=Raf&amp;friendname[]=Billy&amp;fiendemail[]=bily@someemail.com&amp;friendname[]=Andy&amp;fiendemail[]=Andy@somwhere.com&amp;friendname[]=Adam&amp;fiendemail[]=Adam@herenthere.com */ </code></pre> <p>how do I make this data in to a JSON object? which should have the following example JSON data from the above form.</p> <pre><code>{ "MyName":"raf", "friendname":[ {"0":"Bily"}, {"1":"Andy"}, {"2":"Adam"} ], "friendemail":[ {"0":"bily@someemail.com"}, {"1":"Andy@somwhere.com"}, {"2":"Adam@herenthere.com"} ] } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload