• c# DataSet转换为Json


    /// <summary> 
            /// DataSet转换为Json 
            /// </summary> 
            /// <param name="dataSet">DataSet对象</param> 
            /// <returns>Json字符串</returns> 
            public static string ToJson(DataSet dataSet)
            {
                string jsonString = "{";
                foreach (DataTable table in dataSet.Tables)
                {
                    jsonString += """ + table.TableName + "":" + ToJson(table) + ",";
                }
                jsonString = jsonString.TrimEnd(',');
                return jsonString + "}";
            }


     /// <summary>  
            /// DataSet转换成Json格式  
            /// </summary>  
            /// <param name="ds">DataSet</param> 
            /// <returns></returns>  
            public static string Dataset2Json(DataSet ds)
            {
                StringBuilder json = new StringBuilder();
    
                foreach (DataTable dt in ds.Tables)
                {
                    json.Append("{"");
                    json.Append(dt.TableName);
                    json.Append("":");
                    json.Append(DataTable2Json(dt));
                    json.Append("}");
                }
                return json.ToString();
            }
  • 相关阅读:
    poj 3378 Crazy Thairs 夜
    1487. Chinese Football 夜
    容斥原理
    Dancing Links
    三角剖分
    模线性方程模板
    模线性方程
    容斥原理 POJ2773
    DNA Sequence [矩阵]
    hdu 2588 容斥
  • 原文地址:https://www.cnblogs.com/feizianquan/p/9720783.html
Copyright © 2020-2023  润新知