码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-05-29 12:54:18      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:ble   pen   alt   selected   sharp   object   target   open   tostring   

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

 

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

标签:ble   pen   alt   selected   sharp   object   target   open   tostring   

原文地址:http://www.cnblogs.com/jzz20151105/p/6917676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!