Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

So I basically have a modal to add an object, that I want to serialize to JSON Object. To serialize each input will have a name and value of course.

The thing is one of those inputs have a value which is an array (list of ids). This input is actually hidden and I have set it my self.

Following are the steps I followed

  1. Set the hidden input values

    $('input[name="students"]').val(JSON.stringify(idsArray));
    
  2. Serialize the form into object

    action_object = $('.actionForm').serializeObject();
    

    Source for SerialzeObject function Convert form data to JavaScript object with jQuery

  3. Convert to JSON object

    action_JSON = JSON.stringify(action_object);
    
  4. Result is as following

    {"Title":"","students":"[\"2015022\",\"2015027\",\"2015032\"]","ActionType":"3","Description":"yjtkt","Date":"2015-11-17"}
    

Now the object seems ok.

However check for the students array. Is that normal and if not how that can be fixed ?

share|improve this question
    
"Is that normal": Yes. It's the string representation of a string representation of an array containing strings (idsArray) – Andreas Nov 16 '15 at 22:41
    
@Andreas Thanks that helps – Abdel-Rahman Shoman Nov 16 '15 at 22:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.