我正在使用以下代码创建JSON文件
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);
我的JSON看起来像
[{"x":"58770"},{"x":"79035"},{"x":"84030"},{"x":"90145"},{"x":"95630"},{"x":"102580"},{"x":"108950"},{"x":"113615"},{"x":"118765"},{"x":"124055"}]
但我想要类似的东西,
[[58770,79035,84030,90145,95630,102580...]]
我如何实现这一目标,
我想要这个特定的格式来使用这个json作为高亮度图
答案 0 :(得分:2)
您可以通过这种方式在客户端实现这一目标:
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]