Configure Json.NET serialization settings on a class level

前端 未结 1 1814
傲寒
傲寒 2020-12-04 01:38

I want my class to be serialized and deserialized using camel case naming convention. I know I can use the JsonConvert.SerializeObject(object, settings) overloa

相关标签:
1条回答
  • 2020-12-04 02:05

    If you're using Json.NET 9.0.1 or later you can use the NamingStrategyType property on the JsonObjectAttribute to achieve what you want. If you need to pass arguments to the NamingStrategy's constructor then specify them with the NamingStrategyParameters property. Below is an example of how to specify a class with a camel case naming strategy.

    [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
    public class Foo
    {
        public string Bar;
    }
    
    0 讨论(0)
提交回复
热议问题