You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using Fizzler ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using System ;
namespace DS.WMS.PrintApi.Utils
{
public class SemicolonConverter : JsonConverter
{
public override bool CanConvert ( Type objectType )
{
// 指定转换器适用的类型
return typeof ( string ) . IsAssignableFrom ( objectType ) ;
}
public override object ReadJson ( JsonReader reader , Type objectType , object existingValue , JsonSerializer serializer )
{
// 读取JSON时不需要进行任何操作, 因为我们是进行序列化
throw new NotImplementedException ( ) ;
}
public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
{
//new一个JObject对象,JObject可以像操作对象来操作json
var newStr = string . Empty ;
var temp = ( string ) value ;
if ( temp ! = null & & temp . Contains ( ";" ) )
{
// 写入JSON时, 将分号替换为其他字符
string sanitizedValue = temp . Replace ( ";" , "; " ) ;
writer . WriteValue ( sanitizedValue ) ;
}
else
{
writer . WriteValue ( value ) ;
}
}
}
}