Newtonsoft.JSON 自定义JsonConverter
引用:
https://www.cjavapy.com/article/2513/
https://www.cnblogs.com/weihanli/p/11080531.html
https://www.cnblogs.com/Lulus/p/16968656.html
https://www.cjavapy.com/article/2513/
https://www.cnblogs.com/net-sky/p/16563025.html
public class DecimalConverter : JsonConverter
{
public DecimalConverter()
{
}
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(decimal));
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
decimal? dec = value as decimal?;
if (dec == null)
return;
writer.WriteValue((dec.Value).ToString("0.00"));
}
public override bool CanRead
{
get { return false; }
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//do nothing
return existingValue;
}
}