title: asp.net web service : sending json within json
body: <p>I'm using jquery to send a json string to an ASMX web service. The code behind for the web service method definition looks like this:</p>
  
  <pre><code>[WebMethod(EnableSession = true)]
  public string DoMyProcess(string TheDataID, string TheUserID, string TheData) {
  </code></pre>
  
  <p>The string TheData is a javascript object MyObject that I serialize using</p>
  
  <pre><code>var TheData = JSON.stringify(MyObject);
  </code></pre>
  
  <p>The jquery part that sends the json looks like this:</p>
  
  <pre><code>var AjaxData = '{"TheDatatID":"' + DatatID + '","TheUserID":"' + UserID + '","TheData":"' + TheData + '"}';
  
      $.ajax({
        type: "POST",
        url: "../WebServices/MyServices.asmx/DoMyProcess",
        data: AjaxData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: "false",
        success: RequestSuccess,
        error: RequestError
      });
  </code></pre>
  
  <p>As it is, I get a 500 error and the debugger doesn't even fire in VS. However, if I replace var TheData = JSON.stringify(MyObject); with </p>
  
  <pre><code>var TheData = "test";
  </code></pre>
  
  <p>I'm able to get the debugger to break on the first line of the code behind file.</p>
  
  <p>This must be the result of a problem when sending json within json; it should work but it doesn't. What am I missing?</p>