title: Convert datatable to JSON in C#
body: <ol>
  <li>I want to get records from database into a <code>DataTable</code>.  </li>
  <li>Then convert the <code>DataTable</code> into a JSON object.  </li>
  <li>Return the JSON object to my JavaScript function.</li>
  </ol>
  
  <p>I use <a href="https://stackoverflow.com/questions/11138035/convert-datatable-to-json-with-key-per-row#answers-header">this</a> code by calling:</p>
  
  <pre><code>string result = JsonConvert.SerializeObject(DatatableToDictionary(queryResult, "Title"), Newtonsoft.Json.Formatting.Indented);
  </code></pre>
  
  <p>To convert a DataTable to JSON, it works correctly and return the following:</p>
  
  <pre><code>{
      "1": {
      "viewCount": 703,
      "clickCount": 98
      },
      "2": {
      "viewCount": 509,
      "clickCount": 85
      },
      "3": {
      "viewCount": 578,
      "clickCount": 86
      },
      "4": {
      "viewCount": 737,
      "clickCount": 108
      },
      "5": {
      "viewCount": 769,
      "clickCount": 130
      }
  } 
  </code></pre>
  
  <p>But I would like it to return the following:</p>
  
  <pre><code>{"records":[
  {
  "Title": 1,
  "viewCount": 703,
  "clickCount": 98
  },
  {
  "Title": 2,
  "viewCount": 509,
  "clickCount": 85
  },
  {
  "Title": 3,
  "viewCount": 578,
  "clickCount": 86
  },
  {
  "Title": 4,
  "viewCount": 737,
  "clickCount": 108
  },
  {
  "Title": 5,
  "viewCount": 769,
  "clickCount": 130
  }
  ]} 
  </code></pre>
  
  <p><strong>How can I do this?</strong></p>