常用的C#类
程序员文章站
2022-04-13 09:35:01
...
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; ////// DataTableConvertJson 的摘要说明 /// public class DataTableConvertJson { public DataTableConvertJson() { // // TODO: 在此处添加构造函数逻辑 // } #region dataTable转换成Json格式 ////// dataTable转换成Json格式 /// /// ///public static string DataTable2Json(DataTable dt) { StringBuilder jsonBuilder = new StringBuilder(); //jsonBuilder.Append("{\""); //jsonBuilder.Append(dt.TableName); //jsonBuilder.Append("["); jsonBuilder.Append("["); for (int i = 0; i /// DataSet转换成Json格式 /// /// DataSet /// 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(); } #endregion /// /// Msdn /// /// /// ///public static string DataTableToJson(string jsonName, DataTable dt) { StringBuilder Json = new StringBuilder(); Json.Append("{\"" + jsonName + "\":["); if (dt.Rows.Count > 0) { for (int i = 0; i