Default camel case of property names in JSON serialization

后端 未结 7 1057
感情败类
感情败类 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:01

    You can use the provided class Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver:

    var serializer = new JsonSerializer
    {
        ContractResolver = new CamelCasePropertyNamesContractResolver()
    };
    var jobj = JObject.FromObject(request, serializer);
    

    In other words, you don't have to create a custom resolver yourself.

提交回复
热议问题