继承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.Value.ToString();//读取字符串,然后解密 JsonReader jr = new JsonTextReader(new StringReader(data)); if (data.Substring(0, 1).ToString() == "[")//是数组 { JArray jObj = JArray.Load(jr); var obj = serializer.Deserialize<T>(jObj.CreateReader()); return obj; } else { JObject jObj = JObject.Load(jr); var obj = serializer.Deserialize<T>(jObj.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); } }