媽媽再也不用為我轉Json而擔憂了!! 很簡單,沒什麼好說明的,嗯! 1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!IsPostBack) 4 { 5 ToJsonGetData tjgd = new ToJson ...
媽媽再也不用為我轉Json而擔憂了!!
很簡單,沒什麼好說明的,嗯!
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
下載:Json.dll.7z