Default camel case of property names in JSON serialization

后端 未结 7 1095
感情败类
感情败类 2020-12-14 00:35

I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both C# conventions on the back-end and JavaScript conventions on the f

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 01:11

    JObject.FromObject uses default settings from JsonConvert defaults. There is a func property that you can assign like this:

     JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
     {
       ContractResolver = new CamelCasePropertyNamesContractResolver()
     };
    

    and whenever you call Jobject.FromObject, it will use this func to construct settings.

提交回复
热议问题