title: Read and Parse JSON data from POST request in C#
body: <p>I'm doing a POST request via JQuery's Ajax, with the type of data defined as <code>json</code>, containing the values to be posted to server, something like <code>Username: "Ali"</code>.</p>
  
  <p>What I need to do in a Handler, is to read the values, deserialize them to an object named <code>User</code>.</p>
  
  <pre><code>String data = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();
  User user = JsonConvert.DeserializeObject&lt;User&gt;(data);
  </code></pre>
  
  <p>While debugging, the value of <code>data</code> is the following:</p>
  
  <p><code>Username=Ali&amp;Age=2....</code></p>
  
  <p>Now I'm sure this isn't <code>JSON</code>, so the next line would certainly produce an error:</p>
  
  <pre><code>"Unexpected character encountered while parsing value: U. Path '', line 0, position 0."
  </code></pre>
  
  <p>What is the proper way to read <code>JSON</code> data from POST request?</p>
  
  <p><strong>Client Side</strong></p>
  
  <pre><code>$.ajax({
      type: 'POST',
      url: "http://localhost:38504/DeviceService.ashx",
      dataType: 'json',
      data: {
        Username: 'Ali',
        Age: 2,
        Email: 'test'
      },
      success: function (data) {
      },
      error: function (error) {
      }
    });
  </code></pre>