首页 > 代码库 > C# Entity To Json
C# Entity To Json
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; using System.Web.Script.Serialization; /// <summary> /// Summary description for Common /// </summary> public class Common { private static JavaScriptSerializer jss; public static string DataTableToJson(DataTable dt) { if (dt == null || dt.Rows.Count == 0) return ""; int length = dt.Rows.Count; StringBuilder strbuild = new StringBuilder(); strbuild.Append("[");//转换成多个model的形式 for (int i = 0; i < length; i++) { strbuild.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { strbuild.Append("\""); strbuild.Append(dt.Columns[j].ColumnName); strbuild.Append("\":\""); strbuild.Append(dt.Rows[i][j].ToString()); strbuild.Append("\","); } strbuild.Remove(strbuild.Length - 1, 1); strbuild.Append("},"); } strbuild.Remove(strbuild.Length - 1, 1); strbuild.Append("]"); return strbuild.ToString(); } public static string EntityToJson(object obj) { if (null == jss) jss = new JavaScriptSerializer(); return jss.Serialize(obj); } }
C# Entity To Json
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。