Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like your JSON is getting double serialized. Although you did not show your full controller code, I'm guessing that you are doing something like this:</p> <pre><code> public ActionResult GetDataTable() { // (... code to build data table omitted for brevity ...) // Serialize data table using Json.Net to avoid circular reference error string output = JsonConvert.SerializeObject(dt, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); return Json(output); } </code></pre> <p>The <code>Json()</code> method also invokes serialization. Normally, in an MVC controller, you would just use the <code>Json()</code> method to serialize your return object, and not use Json.Net separately. I can see you are using Json.Net here to try to get around the exception that happens due to circular references when you try to serialize a data table. If you are going to serialize manually, then you need to return the data in a way that it will not get serialized a second time. You can do this using the <code>Content()</code> method instead. Try it like this:</p> <pre><code>public ActionResult GetDataTable() { // Build data table DataTable dt = new DataTable(); dt.Columns.Add("DAYDATE", typeof(DateTime)); dt.Columns.Add("SERIES1", typeof(double)); dt.Rows.Add(new DateTime(2012, 5, 22, 0, 15, 0), 3.65); // Serialize data table using Json.Net to avoid circular reference error string output = JsonConvert.SerializeObject(dt, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); // Output is already serialized; return it as is (with the appropriate media type) return Content(output, "application/json"); } </code></pre> <p>In my testing, the above will produce the following output, which I think is what you are looking for:</p> <pre><code>[ { "DAYDATE": "2012-05-22T00:15:00", "SERIES1": 3.65 } ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload