-
.NET中DataSet转化Json工具类
- /**
- * 方法名称:DataSetToJson Beat1.0
- * 参数介绍:
- * ds-数据集 ||
- * JsonName-Json数据的根元素名称 ||
- * ParName-需要转化数据集中名称的数组 ||
- * 此方法为测试小样版,因我的项目需要而生,.
- * 初步打算做成类库.可以转化DataTable等.
- * 完成时间:2008-03-14 白色情人节
- **/
- private string DataSetToJson(DataSet ds,string JsonName,string[] ParName)
- {
- try
- {
- if(ds==null)
- {
- return "DataSet Is Null ,So I Can't Do It To Json!";
- }
- if (JsonName.Length < 1)
- {
- return "You Set The Json Name Is Wrong!";
- }
- if (ds.Tables[0].Columns.Count < ParName.Length)
- {
- return "You Give The ParName Is Bigger Than DataSet Columns!";
- }
- string josn = "{ \"" + JsonName + "\":[";
- string temp = "";
- for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
- {
- temp = temp + "{";
- for (int i = 0; i < ParName.Length; i++)
- {
- temp += "\"" + ParName[i] + "\":\"" + ds.Tables[0].Rows[j][ParName[i]] + "\"";
- if (i != ParName.Length - 1)
- {
- temp = temp + ",";
- }
- }
- temp = temp + "},";
- }
- josn = josn + temp + "]}";
- return josn;
- }
- catch (Exception ex)
- {
- return "Codeing is Error----"+ex.ToString();
- }
- }
复制代码
-
相关阅读:
Win7 vs2017 WDK 1803 1809 驱动开发 出错 KMDF
http 请求 post get 长度限制
IO模式和IO多路复用(阻塞IO、非阻塞IO、同步IO、异步IO等概念)
select/poll 和 epoll 比较
centos查看端口被哪个应用端口占用命令
mysql索引知识简单记录
Spring钩子方法和钩子接口的使用详解
mysql使用自增Id为什么存储比较快
分布式Id教程
如何配置JVM系统属性及获取方式System.getProperty("pname")
-
原文地址:https://www.cnblogs.com/luluping/p/1435428.html
Copyright © 2020-2023
润新知