title: How to convert Json object to cutom class object in web service?
body: <p>I've scenario where I want to insert data into database without post back. there are around 12 to 13 fields which i need to insert. I'm passing DTO from the client side which is actually Json object. Now the problem which i'm facing is how to convert that Json object which i got in webservice to the "class" (in my case class name is User) object. </p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
    $('#&lt;%= btnSaveInfo.ClientID %&gt;').click(function()
    {
          // Initialize the object, before adding data to it.
          //  { } is declarative shorthand for new Object().
          var User = { };
          User.FirstName = $('#&lt;%= txtFirstName.ClientID%&gt;').val();
          User.MiddleName = $('#&lt;%= txtMiddleName.ClientID%&gt;').val();
          User.LastName =  $('#&lt;%=txtLastName.ClientID %&gt;').val();
          User.Gender =  $('table#&lt;%= rdbGenderType.ClientID %&gt; input:radio:checked').val();
          User.DateCreated = Date.UTC();
          User.Description = $('#&lt;%= txtDescription.ClientID%&gt;').val();
          User.DOB = $('#&lt;%= txtDOB.ClientID %&gt;').val();
          User.Location=$('#&lt;%= txtLocation.ClientID %&gt;').val();
          var DTO = {'User' : User};
          var path = 'MyWebService.asmx/AddNewUser';
          $.ajax
          ({
              type: "POST",
              url: path,               
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              data: JSON.stringify(DTO),
              async:false,
              success: function(msg)
              {                       
  
              }   
          }); 
     });
  </code></pre>
  
  <p></p>
  
  <p>as you can see i'm passing the data as  <strong>data: JSON.stringify(DTO),</strong>. Now how do I convert this JSon object into </p>
  
  <pre><code>   [WebMethod]
     [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
     public bool AddNewUser(Object User)
     {
         return UserRepository.AddNewUser(User);
     }
  </code></pre>
  
  <p>In the above case AddNewUser method takes the object of User class. But i'm getting casting error. So how do I convert Json object to the "User" class object?</p>