zoukankan      html  css  js  c++  java
  • ASP.NET Core中返回 json 数据首字母大小写问题

    asp.net core  默认输出的json数据首字母会改成小写,考虑可能是为了前端js的书写习惯,毕竟js 操作大小写敏感。

    在Startup类的ConfigureServices()方法中进行配置,DefaultContractResolver() 原样输出,返回的 json 与后台定义一致

    // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.Configure<CookiePolicyOptions>(options =>
                {
                    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                    options.CheckConsentNeeded = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                    
                });
    
                //options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();//json字符串大小写原样输出
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
                    //.AddJsonOptions(opt => { 
                    //    opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
                    //    });// json字符串大小写原样输出
    
    
            }
  • 相关阅读:
    wap学习记录
    vue router
    webpack 之 缓存处理
    webpack 之 plugin
    webpack 之 loader
    babel实践
    webpack 之 webpack-dev-server自动刷新
    webpack之source map
    vue笔记
    《高性能网站建设指南》笔记
  • 原文地址:https://www.cnblogs.com/zxs-onestar/p/12228556.html
Copyright © 2011-2022 走看看