妈妈再也不用为我转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 }
下载:Json.dll.7z
时间: 2024-10-28 11:12:56