
JOSN.NET
叫我老猫也存在
这个作者很懒,什么都没留下…
展开
-
JSON.NET学习(9)--反序列化对象构造函数处理(三)
public class Website{ public string Url { get; set; } public Website(Website website) { //todo... } public Website(int value) { //todo... }}string json = @"{'Url':'http://www.google.com'}";try{ //当反序列化对象无.原创 2021-11-02 14:57:49 · 114 阅读 · 0 评论 -
JSON.NET学习(9)--反序列化对象构造函数处理(四)
public class Website{ public string Url { get; set; } private Website() { } public Website(Website website) { if (website == null) { throw new ArgumentNullException(nameof(website)); }原创 2021-11-02 14:57:22 · 157 阅读 · 0 评论 -
JSON.NET学习(9)--反序列化对象构造函数处理(二)
public class Website{ public string Url { get; set; } public Website(int value) { //todo... }}string json = @"{'Url':'http://www.google.com'}";try{ //当反序列化对象无默认构造函数但存在一个重载构造函数时,反序列化会只调用重载构造函数 var web = JsonConvert.Deseri.原创 2021-10-29 13:33:09 · 227 阅读 · 0 评论 -
JSON.NET学习(9)--反序列化对象构造函数处理(一)
//存在默认构造函数(无论显示还是隐式)public class Website{ public string Url { get; set; } public Website() { //todo... } public Website(Website website) { //todo... } public Website(int value) { //todo... }}原创 2021-10-29 13:29:50 · 551 阅读 · 0 评论 -
JSON.NET学习(8)--使用JSON中的值填充现有的对象实例
public class Account{ public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public List<string> Roles { get; set; }}//声明一个对象,并初始化Account account = new Account{ Email = "j原创 2021-10-29 11:44:08 · 161 阅读 · 0 评论 -
JSON.NET学习(7)--反序列化文件
public class Movie{ public string Name { get; set; } public int Year { get; set; }}// read file into a string and deserialize JSON to a typeMovie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));// deser原创 2021-10-29 11:35:04 · 93 阅读 · 0 评论 -
JSON.NET学习(5)--三种常见JSON反序列化
//反序列化对象public class Account{ public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public IList<string> Roles { get; set; }}string json = @"{ 'Email': 'james@example.com',原创 2021-10-29 11:20:57 · 449 阅读 · 0 评论 -
JSON.NET学习(4)--枚举序列化
List<StringComparison> stringComparisons = new List<StringComparison>{ StringComparison.CurrentCulture, StringComparison.Ordinal};//不使用JsonConverter,枚举序列化结果是对应的数值string jsonWithoutConverter = JsonConvert.SerializeObject(stringCompar原创 2021-10-29 11:16:46 · 406 阅读 · 0 评论 -
JSON.NET学习(3)--序列化到本地文件
public class Movie{ public string Name { get; set; } public int Year { get; set; }}static void Main(string[] args){ Movie movie = new Movie { Name = "Bad Boys", Year = 1995 }; // serialize JSON to a string and then writ原创 2021-10-29 10:44:11 · 192 阅读 · 0 评论 -
JSON.NET学习(2)--三种基本序列化
JOSN.NET序列化对象。public class Account{public string Email { get; set; }public bool Active { get; set; }public DateTime CreatedDate { get; set; }public IList Roles { get; set; }}Account account = new Account{Email = “james@example.com”,Active = true原创 2021-10-29 10:28:21 · 125 阅读 · 0 评论 -
JSON.NET学习(1)--JOSN结构
JSON结构介绍:JSON的两种结构JSON有两种表示结构,对象和数组。 1-1:对象结构以”{”大括号开始,以”}”大括号结束。中间部分由0或多个以”,”分隔的”key(关键字)/value(值)”对构成,关键字和值之间以”:”分隔,语法结构如代码。{key1:value1,key2:value2,…}1-2数组结构以”[”开始,”]”结束。中间由0或多个以”,”分隔的值列表组成,语法结构如代码。[{key1:value1,key2:value2},{key3:valu原创 2021-10-29 10:14:19 · 91 阅读 · 0 评论