首页 > 代码库 > C#匿名对象序列化

C#匿名对象序列化

//匿名对象序列化
var obj=new { Name = "张三", Age = 15 };
Console.WriteLine(JsonConvert.SerializeObject(obj));

//匿名集合序列化
List<object> list = new List<object>();
list.Add(new { Name = "张三", Age = 15 });
list.Add(new { Name = "张三2", Age = new {Add="重庆",Birth="2016-09-01" } });

Console.WriteLine(JsonConvert.SerializeObject(list));

 

C#匿名对象序列化