屌丝技能--转Json(Newtonsoft.Json.dll)

时间:2022-06-05 12:08:14

妈妈再也不用为我转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; }
}

  

 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ToJsonGetData tjgd = new ToJsonGetData();
DataTable dt = tjgd.GetData1();
ShowTablePage stp = new ShowTablePage { total = dt.Rows.Count, rows = dt };
var obj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.FromObject(stp);
string json = obj.ToString(); List<ToJsonENTITY> listEn = tjgd.GetData2();
ShowTablePage<ToJsonENTITY> stp2 = new ShowTablePage<ToJsonENTITY> { total = listEn.Count, rows = listEn };
obj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.FromObject(stp2);
json = obj.ToString(); Response.Write(json);
}
}

下载:Json.dll.7z