1.序列化啊  宝贝!!

public string DataTableToJsonWithJsonNet(DataTable table)
{
string jsonString=string.Empty;
jsonString = JsonConvert.SerializeObject(table);
return jsonString;
}

  

2.还有一个恶心点的方法

public string DataTableToJson(DataTable table)
{
var JsonString = new StringBuilder();
if (table.Rows.Count > )
{
JsonString.Append("[");
for (int i = ; i < table.Rows.Count; i++)
{
JsonString.Append("{");
for (int j = ; j < table.Columns.Count; j++)
{
if (j < table.Columns.Count - )
{
JsonString.Append("\"" + table.Columns[j].ColumnName.ToString()
+ "\":" + "\"" + table.Rows[i][j].ToString() + "\",");
}
else if (j == table.Columns.Count - )
{
JsonString.Append("\"" + table.Columns[j].ColumnName.ToString()
+ "\":" + "\"" + table.Rows[i][j].ToString() + "\"");
}
}
if (i == table.Rows.Count - )
{
JsonString.Append("}");
}
else
{
JsonString.Append("},");
}
}
JsonString.Append("]");
}
return JsonString.ToString();
}

自定义格式化

最新文章

  1. Node.js教程系列~目录
  2. PeopleSoft Rich Text Boxes上定制Tool Bars
  3. python使用xlrd模块读写excel
  4. 如何让你的UWP应用程序无缝调用几何作图
  5. java开发中的23中设计模式详解--大话设计模式
  6. iconfont-矢量图标字体的运用
  7. UVa 二叉树的编号(二叉树)
  8. iptable软路由
  9. Windows8.1 安装office2013并激活
  10. 转 如何使用velocity模板引擎开发网站
  11. redo文件二
  12. 一起啃PRML - 1.2.4 The Gaussian distribution 高斯分布 正态分布
  13. 关于git服务器的搭建
  14. JS中$含义和用法
  15. java 各种数据类型判断为空
  16. Harbor使用 -- 修改80端口
  17. go 排序sort的使用
  18. MT【61】含参数二次函数最大最小值
  19. uWSGI, Gunicorn, 啥玩意儿?
  20. php 批量导入昨天的数据(别类版的增量备份安案)

热门文章

  1. SEO概念及SEO相关优化
  2. android sqlite no such table
  3. 《T-SQL查询》读书笔记Part 1.逻辑查询处理知多少
  4. 设计模式的征途—17.模板方法(Template Method)模式
  5. &ldquo;史上更难就业季&rdquo;暴露出啥隐情?
  6. 【手记】ASP.NET提示“未能创建类型”处理
  7. spring boot -Properties &amp; configuration
  8. redis与python交互
  9. 玩转JPA(一)---异常:Repeated column in mapping for entity/should be mapped with insert=&quot;false&quot; update=&quot;fal
  10. Oracle 重建控制文件一例