Ensuring json keys are lowercase in .NET

后端 未结 5 2063
生来不讨喜
生来不讨喜 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:07

    protected void Application_Start() {
        JsonConfig.Configure();   
    }
    
    public static class JsonConfig
    {
        public static void Configure(){
            var formatters = GlobalConfiguration.Configuration.Formatters;
            var jsonFormatter = formatters.JsonFormatter;
            var settings = jsonFormatter.SerializerSettings;
    
            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        }
    }
    

提交回复
热议问题