C#使用Newtonsoft序列化、反序列化

来源:互联网 发布:python爬虫设置代理ip 编辑:程序博客网 时间:2024/05/14 02:33

  public class Product    {        public string Name { get; set; }        public double Price { get; set; }        public override string ToString()        {            return "Name: " + Name + ", Price: " + Price;        }    }

Product product = new Product();product.Name = "青椒";product.Price = 1.5;string serializerJson = JsonConvert.SerializeObject(product);Product pro = (Product) JsonConvert.DeserializeObject<Product>(serializerJson);// Product pro = (Product)JsonConvert.DeserializeObject(serializerJson, typeof (Product)); // 重载方法


1 0
原创粉丝点击