How to pass checkbox values to a Json Object in ajax/jquery
<p>Need to create a json object like this:
Course names are checkbox values</p>

<p>Ex:</p>

<pre><code>{
  "name" : "abc",
  "branch" : "Computers",
  "courses" : [ {
                   "courseName":"java"
                },

               {
                  "courseName":"C"
               }
        ]
}
</code></pre>

<p>For this, </p>

<p>I got the values of checkbox like this:</p>

<pre><code>   var listOfCourses = [];
    $('#courses:checked').each(function() {

        listOfCourses.push($(this).val());

     });
</code></pre>

<p>I created student json object:</p>

<pre><code>var student = {
        name : $('#name').val(),
        branch : $("#branch").val(),
        courses : courses
    }
</code></pre>

<p>courses should have the checkbox values as described in the example.</p>

<p>So how do I pass the values in courses?</p>

<p>Ajax function looks like this :</p>

<pre><code>$.ajax({
        url : "http://localhost:8080/StudentRegistration/rest/register",
        data : JSON.stringify(student),
        type : "POST",
        contentType : "application/json",
        success : function(data) {
            alert("success" + data);

        },
        error : function(data) {
            alert("error " + data);
        }
    });
</code></pre>

<p>Please help.</p>