【Newtonsoft.Json Json.Net】02.01、序列化设置Serialization Settings
JsonSerializer有多个属性,用于自定义如何序列化JSON。这些也可以通过JsonSerializerSettings参数,在JsonConvert上使用。 属性的用法: {//JsonConvert
string json = "";
var serializerSettings = new JsonSerializerSettings
{
Da
{//JsonConvert
string json = "";
var serializerSettings = new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.IsoDateFormat,ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,//ContractResolver = new.. .//MassTransit contract resolver that includes private setters
};
PageInfo obj = JsonConvert.DeserializeObject<PageInfo>(json,serializerSettings);
}
{//JsonSerializer
PageInfo obj = new PageInfo();
JsonSerializer serializer = new JsonSerializer();
serializer.DateFormatHandling = DateFormatHandling.IsoDateFormat;
using (StreamWriter sw = new StreamWriter(@"c:\json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer,obj);
}
}
DateFormatHandling
MissingMemberHandling
ReferenceLoopHandling
NullValueHandling
DefaultValueHandling
ObjectCreationHandling
TypeNameHandling
TypeNameAssemblyFormat
SerializationBinder
MetadataPropertyHandling
ConstructorHandling
Converters
ContractResolver
TraceWriter
Error
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。