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

妈妈再也不用为我转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-08-24 15:19:57

屌丝技能--转Json(Newtonsoft.Json.dll)的相关文章

C# 解析json Newtonsoft.Json

Newtonsoft.Json.dll public class ErrorInfo { public error_response error_response { get; set; } } public class error_response { public string code { get; set; } public string zh_desc { get; set; } public string en_desc { get; set; } } //嵌套性数据 // {"er

.Net使用Newtonsoft.Json.dll(JSON.NET)对象序列化成json、反序列化json示例教程

JSON作为一种轻量级的数据交换格式,简单灵活,被很多系统用来数据交互,作为一名.NET开发人员,JSON.NET无疑是最好的序列化框架,支持XML和JSON序列化,高性能,免费开源,支持LINQ查询.目前已被微软集成于webapi框架之中,因此,熟练掌握JSON.NET相当重要,这篇文章是零度参考官网整理的示例,通过这些示例,可以全面了解JSON.NET提供的功能. Newtonsoft.Json的地址: 官网:http://json.codeplex.com/ 源码地址:https://gi

使用Newtonsoft.Json.dll(JSON.NET)动态解析JSON、.net 的json的序列化与反序列化(一)

在开发中,我非常喜欢动态语言和匿名对象带来的方便,JSON.NET具有动态序列化和反序列化任意JSON内容的能力,不必将它映射到具体的强类型对象,它可以处理不确定的类型(集合.字典.动态对象和匿名对象),在这篇文章中我将通过JToken.JObject和JArray来动态解析JSON对象,使它很容易创建和检索的JSON内容而无需基础类型.通过JObject和JArray创建JSON对象我们先用非常简单的方法来动态创建一些JSON,可通过JToken派生的JSON.NET对象来进行,最常见的JTo

Newtonsoft.Json code

序列化 Product product = new Product(); product.ExpiryDate = new DateTime(2008, 12, 28); JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new JavaScriptDateTimeConverter()); serializer.NullValueHandling = NullValueHandling.Ign

更新Newtonsoft.Json后报异常,未能加载文件或程序集“Newtonsoft.Json

未能加载文件或程序集“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项.找到的程序集清单定义与程序集引用不匹配. (异常来自 HRESULT:0x80131040) 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.IO.FileLoadExceptio

Newtonsoft.Json 把对象转换成json字符串

var resultJson = new { records = rowCount, page = pageindex, //总页数=(总页数+页大小-1)/页大小 total = (rowCount + pagesize - 1) / pagesize,//总页数 rows = data.ToList<Web.Entity.Db.Table1Bean>(), }; //JsonResult jr = Json(resultJson, "application/json",

C#.NET序列化XML、JSON、二进制微软自带DLL与newtonsoft(json.net)

序列化是将对象转换成另一种格式(XML.json.二进制byte[]) JSON序列化 .NET中有三种常用的JSON序列化的类,分别是: Newtonsoft.Json.JsonConvert类(推荐) Newtonsoft.Json.JsonConvert类是非微软提供的一个JSON序列化和反序列的开源免费的类库(下载网址是:http://www.codeplex.com/json/),它提供了更灵活的序列化和反序列化控制,并且如果你的开发环境使用的是.NET Framework3.5及以后

WCF JSON DATETIME JSON.NET (Newtonsoft.Json.dll)

[DataMember] public DateTime? myTime { get; set; } var timeFormat = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; string json = JsonConvert.SerializeObject(send, timeFormat); ResultData rd = JsonConvert

C# 通过Newtonsoft.Json.dll序列化日期的处理

Newtonsoft.Json.dll提供了非常好的Json序列化和反序列化方式,但是对日期的处理却让我纠结了很久.首先定义类如下: public class Student{ public int Id{get;set;} public string Name{get;set;} public DateTime BirthDay{get;set;} } 序列化代码如下: Student stu = new Student() { Id = 1, Name = "zhangsan",