如何 DataTable格式转换json格式
2024-10-19 04:27:00
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();
}
自定义格式化
最新文章
- Node.js教程系列~目录
- PeopleSoft Rich Text Boxes上定制Tool Bars
- python使用xlrd模块读写excel
- 如何让你的UWP应用程序无缝调用几何作图
- java开发中的23中设计模式详解--大话设计模式
- iconfont-矢量图标字体的运用
- UVa 二叉树的编号(二叉树)
- iptable软路由
- Windows8.1 安装office2013并激活
- 转 如何使用velocity模板引擎开发网站
- redo文件二
- 一起啃PRML - 1.2.4 The Gaussian distribution 高斯分布 正态分布
- 关于git服务器的搭建
- JS中$含义和用法
- java 各种数据类型判断为空
- Harbor使用 -- 修改80端口
- go 排序sort的使用
- MT【61】含参数二次函数最大最小值
- uWSGI, Gunicorn, 啥玩意儿?
- php 批量导入昨天的数据(别类版的增量备份安案)
热门文章
- SEO概念及SEO相关优化
- android sqlite no such table
- 《T-SQL查询》读书笔记Part 1.逻辑查询处理知多少
- 设计模式的征途—17.模板方法(Template Method)模式
- &ldquo;史上更难就业季&rdquo;暴露出啥隐情?
- 【手记】ASP.NET提示“未能创建类型”处理
- spring boot -Properties &; configuration
- redis与python交互
- 玩转JPA(一)---异常:Repeated column in mapping for entity/should be mapped with insert=";false"; update=";fal
- Oracle 重建控制文件一例