摘要: Json序列化器为序列化及反序列化集合对象提供了良好的支持.->Serializing 为了序列化一个集合---一个泛型的list,array,dictionary,或者自定义集合---简单地调用序列化器,使用您想要进行序列化的集合对象作为参数,Json.Net会序列化集合以及所有它包含的值。示例:public class Product { public string Name { get; set; } public decimal Price { get; set; } [JsonConverter(typeof(IsoDateTimeConverter))] public Dat 阅读全文
posted @ 2011-06-11 15:09 资源收集 阅读(712) 评论(0) 推荐(0) 编辑
摘要: Json.Net支持序列化回调方法,回调方法通过Json序列化器(JsonSerializer)可以用来操作一个对象,在它被序列化和反序列化之前或者之后.OnSerializing OnSerialized OnDeserializing OnDeserialized为了告诉序列化器在对象的序列化生命周期中哪个方法应该被调用,需要用适当的attribute(OnSerializingAttribute, OnSerializedAttribute, OnDeserializingAttribute, OnDeserializedAttribute)来标记方法.例如对象序列化的回调方法:usin 阅读全文
posted @ 2011-06-11 15:09 资源收集 阅读(583) 评论(0) 推荐(0) 编辑
摘要: using Newtonsoft.Json.Linq;定义类: public class Product { public string Name { get; set; } public DateTime Expiry { get; set; } public decimal Price { get; set; } public string[] Sizes { get; set; } }测试: Product product = new Product { Name = "Apple", Expiry = new DateTime(2010, 12, 18), Pric 阅读全文
posted @ 2011-06-11 15:03 资源收集 阅读(668) 评论(0) 推荐(0) 编辑
摘要: 使用Newtonsoft.Json这是一个开源的Json.Net库。下载地址:http://json.codeplex.com/releases/view/50552。当前版本为 Release 8从下载到的源代码中获取Newtonsoft.Json.Net20.dll,添加到自己的工程中。using Newtonsoft.Json;定义类:public class Message { public string Address { get; set; } [JsonProperty(TypeNameHandling = TypeNameHandling.All)] public object 阅读全文
posted @ 2011-06-11 15:02 资源收集 阅读(1001) 评论(0) 推荐(0) 编辑