zoukankan      html  css  js  c++  java
  • .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();
  •         }

  •     }
查看全文
  • 相关阅读:
    spring在加Transactional的方法中使用redis取值为空的问题
    IDEA 调试jar文件
    搭建maven私有中央仓库
    F2BPM的流程仿真
    F2BPM流程中心RESTfull解决方案及示例
    F2BPM中关于工作流引擎驳回设计
    “员工请假”流程及在线表单开发示例
    在线表单字段做为节点处理人
    F2工作流引擎之-纯JS Web在线可拖拽的流程设计器(八)
    【原创】工作流引擎运转模型之--终极利器退回时回收分支算法
  • 原文地址:https://www.cnblogs.com/a13971240/p/1502220.html
  • Copyright © 2011-2022 走看看