Formatting output of Newtonsoft.Json.JsonConvert.SerializeObject(dataSet) [duplicate]

放肆的年华 提交于 2019-12-04 19:28:41

You could just convert the datatable to the format you need using a linq projection:

Newtonsoft.Json.JsonConvert.SerializeObject(
 dataTable.Select(
  d => new {
   Names = d.Columns.Select(c => c.ColumnName).ToArray(),
   Values = d.Rows.Select(r => r.ToArray()).ToArray()
  })
);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!