javascript - How to convert jQuery.serialize() data to JSON object? -


Is there a better way to convert fire data that is already sorted by jQuery function serialize () Multiple input array fields in the form I want to be able to transform form data into a JSON object to recreate some other informative tables. Let me tell you a better way of getting the converted serialized string as a JSON object.

  & lt; Form id = 'sampleform' & gt; & Lt; Input name = 'MyName' type = 'text' / & gt; // RF & lt ;! - Array input field below - & gt; & Lt; Input name = 'friend name []' type = 'text' / & gt; // Bulli & lt; Input name = 'finemlem []' type = 'text' / & gt; // bily@someemail.com & lt ;! - Duplicate field below to add more friends - & gt; & Lt; Input name = 'friend name []' type = 'text' / & gt; // Andy & lt; Input name = 'fiendemail []' type = 'text' / & gt; // Andy@somwhere.com & lt; Input name = 'friend name []' type = 'text' / & gt; // Adam & lt; Input name = 'fiendemail []' type = 'text' / & gt; // Adam@herenthere.com & lt; / Form & gt;  

Apply jquery method to get data

  var MyForm = $ ("# sampleform"). Serialize (); / ** Result: MyName = Raf and Friendship [] = Billy & amp; Fiendemail [] = bily@someemail.com& Friendname [] = Andy & amp; Fiendemail [] = Andy@somwhere.com& Friendname [] = Adam & amp; Fiendemail [] =Adam@herenthere.com * /  

How do I make this data in JSON object? The following example should be in the form of above JSON data. "{{": "Bily"}, {"1": "Andy"}, {"2": "Ryan": " "{{": "Bily@someemail.com"}, {"1": "Andy @ submitted"), {"2": "Adam@herenthere.com"}} / Code>

  var formadata = $ ("#mayform"). Serialize (); Var data = {}; $ (Formdata) .each (function (index, obje) {data [obj.name] = obj.value;});  

Simple and fast;)


Comments