title: How to Deserialize string using Newtonsoft.Json library into custom object using C#
body: <p>I have a .NET 3.5 project. In ajax call I create json object like this:</p>
  
  <pre><code>var jsonAOData = JSON.stringify(aoData);
  ...
  data: "{jsonAOData : '" + jsonAOData + "'}"
  ...
  </code></pre>
  
  <p>then I pass it to a code behind WebMethod</p>
  
  <pre><code>[WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public static string jQueryDataTable(string jsonAOData)
  {
  // Deserialize json into object
  var customObj = JsonConvert.DeserializeObject&lt;List&lt;NameValue&gt;&gt;(jsonAOData);
  </code></pre>
  
  <p>I need to deserialize the object into a CustomParams object. </p>
  
  <p>Here my object:</p>
  
  <pre><code>[Serializable]
  public class NameValue
  {
      public string Name { get; set; }
      public string Value { get; set; }
  }
  
  [Serializable]
  public class CustomParams
  {
      public string sEcho { get; set; }
      public string iColumns { get; set; }
      public string sColumns { get; set; }
      public string iDisplayStart { get; set; }
      public string iDisplayLength { get; set; }
      public string mDataProp_0 { get; set; }
      public string sSearch_0 { get; set; }
      public string bRegex_0 { get; set; }
      public string MyProperty { get; set; }
      public string bSearchable_0 { get; set; }
      public string bSortable_0 { get; set; }
      public string mDataProp_1 { get; set; }
      public string sSearch_1 { get; set; }
      public string bRegex_1 { get; set; }
      public string bSearchable_1 { get; set; }
      public string bSortable_1 { get; set; }
      public string mDataProp_2 { get; set; }
      public string sSearch_2 { get; set; }
      public string bRegex_2 { get; set; }
      public string bSearchable_2 { get; set; }
      public string bSortable_2 { get; set; }
      public string mDataProp_3 { get; set; }
      public string sSearch_3 { get; set; }
      public string bRegex_3 { get; set; }
      public string bSearchable_3 { get; set; }
      public string bSortable_3 { get; set; }
      public string mDataProp_4 { get; set; }
      public string sSearch_4 { get; set; }
      public string bRegex_4 { get; set; }
      public string bSearchable_4 { get; set; }
      public string bSortable_4 { get; set; }
      public string mDataProp_5 { get; set; }
      public string sSearch_5 { get; set; }
      public string bRegex_5 { get; set; }
      public string bSearchable_5 { get; set; }
      public string bSortable_5 { get; set; }
      public string mDataProp_6 { get; set; }
      public string sSearch_6 { get; set; }
      public string bRegex_6 { get; set; }
      public string bSearchable_6 { get; set; }
      public string bSortable_6 { get; set; }
      public string mDataProp_7 { get; set; }
      public string sSearch_7 { get; set; }
      public string bRegex_7 { get; set; }
      public string bSearchable_7 { get; set; }
      public string bSortable_7 { get; set; }
      public string sSearch { get; set; }
      public string bRegex { get; set; }
      public string iSortCol_0 { get; set; }
      public string sSortDir_0 { get; set; }
      public string iSortingCols { get; set; }
  
  }
  </code></pre>
  
  <p>I would gladly provide more information if needed. Thanks.</p>
  
  <p>Update:</p>
  
  <p>I have customObj with all the Names, Values
  Screen is attached:</p>
  
  <p><img src="https://i.stack.imgur.com/VHkMq.png" alt="enter image description here"></p>
  
  <p>I need to still transfer all that data into CustomParams.</p>
  
  <p>This is a data from debugger code behind for jsonAOData (just a string) that is passed into </p>
  
  <pre><code>string jsonAOData
  </code></pre>
  
  <p>Here a data:</p>
  
  <pre><code>[{\"name\":\"sEcho\",\"value\":1},{\"name\":\"iColumns\",\"value\":8},{\"name\":\"sColumns\",\"value\":\",,,,,,,\"},{\"name\":\"iDisplayStart\",\"value\":0},{\"name\":\"iDisplayLength\",\"value\":10},{\"name\":\"mDataProp_0\",\"value\":0},{\"name\":\"sSearch_0\",\"value\":\"\"},{\"name\":\"bRegex_0\",\"value\":false},{\"name\":\"bSearchable_0\",\"value\":true},{\"name\":\"bSortable_0\",\"value\":true},{\"name\":\"mDataProp_1\",\"value\":1},{\"name\":\"sSearch_1\",\"value\":\"\"},{\"name\":\"bRegex_1\",\"value\":false},{\"name\":\"bSearchable_1\",\"value\":true},{\"name\":\"bSortable_1\",\"value\":true},{\"name\":\"mDataProp_2\",\"value\":2},{\"name\":\"sSearch_2\",\"value\":\"\"},{\"name\":\"bRegex_2\",\"value\":false},{\"name\":\"bSearchable_2\",\"value\":true},{\"name\":\"bSortable_2\",\"value\":true},{\"name\":\"mDataProp_3\",\"value\":3},{\"name\":\"sSearch_3\",\"value\":\"\"},{\"name\":\"bRegex_3\",\"value\":false},{\"name\":\"bSearchable_3\",\"value\":true},{\"name\":\"bSortable_3\",\"value\":true},{\"name\":\"mDataProp_4\",\"value\":4},{\"name\":\"sSearch_4\",\"value\":\"\"},{\"name\":\"bRegex_4\",\"value\":false},{\"name\":\"bSearchable_4\",\"value\":true},{\"name\":\"bSortable_4\",\"value\":true},{\"name\":\"mDataProp_5\",\"value\":5},{\"name\":\"sSearch_5\",\"value\":\"\"},{\"name\":\"bRegex_5\",\"value\":false},{\"name\":\"bSearchable_5\",\"value\":true},{\"name\":\"bSortable_5\",\"value\":true},{\"name\":\"mDataProp_6\",\"value\":6},{\"name\":\"sSearch_6\",\"value\":\"\"},{\"name\":\"bRegex_6\",\"value\":false},{\"name\":\"bSearchable_6\",\"value\":true},{\"name\":\"bSortable_6\",\"value\":true},{\"name\":\"mDataProp_7\",\"value\":7},{\"name\":\"sSearch_7\",\"value\":\"\"},{\"name\":\"bRegex_7\",\"value\":false},{\"name\":\"bSearchable_7\",\"value\":true},{\"name\":\"bSortable_7\",\"value\":true},{\"name\":\"sSearch\",\"value\":\"\"},{\"name\":\"bRegex\",\"value\":false},{\"name\":\"iSortCol_0\",\"value\":0},{\"name\":\"sSortDir_0\",\"value\":\"asc\"},{\"name\":\"iSortingCols\",\"value\":1}]"
  </code></pre>
  
  <p>My final code looks like this:</p>
  
  <pre><code>    [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public static string jQueryDataTable(string jsonAOData)
      {
          // Deserialize json into object             
          List&lt;NameValue&gt; jsonData = JsonConvert.DeserializeObject&lt;List&lt;NameValue&gt;&gt;(jsonAOData);
          CustomParams paramObject = new CustomParams();
          paramObject.sEcho = jsonData.Single(o=&gt; o.Name == "sEcho").Value;
          paramObject.iColumns = jsonData.Single(o=&gt;o.Name == "iColumns").Value;
          // the rest of the parameters
  
          // ... code ...
      }
  </code></pre>