继承JsonConverter特性
public class ObjJsonConverter<T> : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(T); } //读取 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType.Equals(JsonToken.String)) { string data = reader.ToString();//读取字符串,然后解密 JObject jArray = JObject.FromObject(data); var obj = serializer.Deserialize<T>(jArray.CreateReader()); return obj; } else { JObject jArray = JObject.Load(reader); var obj = serializer.Deserialize<T>(jArray.CreateReader()); return obj; } } //写数据 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteValue(value); } }