How to serialize object to json with type info using Newtonsoft.Json?

前端 未结 3 1102
滥情空心
滥情空心 2020-12-15 16:53

I want to have a property with type name in JSON when I serialize objects of certain types. I wrote a converter:

public class TypeInfoConverter : JsonConvert         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 17:16

    var jsonSerializerSettings = new JsonSerializerSettings() { 
        TypeNameHandling = TypeNameHandling.All
    };
    var json = JsonConvert.SerializeObject(instance, jsonSerializerSettings);
    

    http://james.newtonking.com/json/help/index.html?topic=html/SerializationSettings.htm

提交回复
热议问题