Ensuring json keys are lowercase in .NET

后端 未结 5 2061
生来不讨喜
生来不讨喜 2020-11-28 02:25

Is there simple way using JSON in .NET to ensure that the keys are sent as lower case?

At the moment I\'m using the newtonsoft\'s Json.NET library and simply using

5条回答
  •  生来不讨喜
    2020-11-28 03:06

    you can use "JsonProperty":

    Usage:

    public class Authority
    {
        [JsonProperty("userName")] // or [JsonProperty("username")]
        public string Username { get; set; }
        [JsonProperty("apiToken")] // or [JsonProperty("apitoken")]
        public string ApiToken { get; set; }
    }
    
    var json  = JsonConvert.SerializeObject(authority);
    

提交回复
热议问题