当前位置:首页 > Web开发 > 正文

DefaultContractResolver() 原样输出

2024-03-31 Web开发

标签:

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字符串巨细写原样输出 }

ASP.NET Core中返回 json 数据首字母巨细写问题

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31116.html