Diaosi skills -- convert to Json (Newtonsoft. Json. dll), newtonsoft. json. dll
Mom no longer worries about converting Json !!
It's very simple. There's nothing to explain, um!
public class ShowTablePage<T> where T : class, new() { public int total { get; set; } public List<T> rows { get; set; } } public class ShowTablePage { public int total { get; set; } public DataTable rows { get; set; } } public class ShowCombobox { public int id { get; set; } public string text { get; set; } public string group { get; set; } public bool selected { get; set; } public List<ShowCombobox> children { get; set; } } public class ResultMessage<T> { public ResultMessage() { } public int Code { get; set; } public T Msg { get; set; } }
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!IsPostBack) 4 { 5 ToJsonGetData tjgd = new ToJsonGetData(); 6 DataTable dt = tjgd.GetData1(); 7 ShowTablePage stp = new ShowTablePage { total = dt.Rows.Count, rows = dt }; 8 var obj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.FromObject(stp); 9 string json = obj.ToString();10 11 12 List<ToJsonENTITY> listEn = tjgd.GetData2();13 ShowTablePage<ToJsonENTITY> stp2 = new ShowTablePage<ToJsonENTITY> { total = listEn.Count, rows = listEn };14 obj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.FromObject(stp2);15 json = obj.ToString();16 17 Response.Write(json);18 }19 }
View Code
Download: Json.dll.7z