【问题标题】:JSON format is not supported by highchart [closed]highchart不支持JSON格式[关闭]
【发布时间】:2013-12-15 13:55:30
【问题描述】:

我正在使用以下代码创建一个 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 的 highchart

【问题讨论】:

  • 你从数据库中选择了什么?
  • 我正在选择单列和最后 10 个数据

标签: c# asp.net json highcharts


【解决方案1】:

您可以通过这种方式在客户端实现:

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]

【讨论】:

  • 我如何在客户端获取这个 JSON?
  • 检查一些其他类似的问题,例如this one
猜你喜欢
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
  • 1970-01-01
  • 2010-12-18
  • 1970-01-01
  • 2016-07-01
  • 1970-01-01
相关资源
最近更新 更多