0

I am creating a JSON file using the following code

StringBuilder str = new StringBuilder();
        SqlConnection con = new SqlConnection("Data Source=INBDQ2WK2LBCD2S\\SQLEXPRESS;Initial Catalog=MCAS;Integrated Security=SSPI");
        SqlDataAdapter adp = new SqlDataAdapter("select top 10 x from test4 order by Id desc", con);
        dt = new DataTable();
        adp.Fill(dt);

        DATA = JsonConvert.SerializeObject(dt, new Newtonsoft.Json.Formatting());
        Response.Write(DATA);

My JSON looks like

  [{"x":"58770"},{"x":"79035"},{"x":"84030"},{"x":"90145"},{"x":"95630"},{"x":"102580"},{"x":"108950"},{"x":"113615"},{"x":"118765"},{"x":"124055"}]  

But I want something like,

[[58770,79035,84030,90145,95630,102580...]]

How do I achieve this,

I want this specific format for using this json for highchart

SPandya
  • 1,161
  • 4
  • 26
  • 63

1 Answers1

2

You can achieve that on client side this way:

var d = [{"x":"58770"},{"x":"79035"},{"x":"84030"},{"x":"90145"},{"x":"95630"},{"x":"102580"},{"x":"108950"},{"x":"113615"},{"x":"118765"},{"x":"124055"}],
    dLen = d.length,
    ret = [];

for(var i = 0; i < dLen; i++) { 
    ret.push( parseInt(d[i].x, 10));
}

// ret contains: [58770, 79035, 84030, 90145, 95630, 102580, 108950, 113615, 118765, 124055]
Paweł Fus
  • 44,795
  • 3
  • 61
  • 77