从ASP .Net Core 1.0.0-rc2-final交换为1.0.0时,JSON属性现在小写 [英] JSON properties now lower case on swap from ASP .Net Core 1.0.0-rc2-final to 1.0.0
问题描述
我刚刚将项目从ASP .Net Core 1.0.0-rc2-final交换为1.0.0.由于JSON属性的大写,我们的网站和客户端已停止工作.例如,此行JavaScript现在失败
I've just swapped our project from ASP .Net Core 1.0.0-rc2-final to 1.0.0. Our website and client have stopped working because of the capitalization of JSON properties. For example, this line of JavaScript now fails
for (var i = 0; i < collection.Items.length; i++){
因为控制器现在将数组称为"items"而不是"Items".除了安装更新的软件包和编辑project.json文件外,我没有做任何更改.我还没有更改仍会使用其属性的C#模型文件.
because the controller now calls the array "items" instead of "Items". I have made no changes beyond installing the updated packages and editing the project.json file. I have not changed the C# model files which still capitalize their properties.
为什么ASP.Net Core控制器开始返回具有小写属性的JSON?我该如何回到他们的手中,以尊重模型中属性名称的大小写?
Why have the ASP.Net Core controllers started returning JSON with lower-cased properties? How do I go back to them honoring the case of the property names from the model?
推荐答案
MVC现在默认情况下使用驼峰式案例名称对JSON进行序列化
MVC now serializes JSON with camel case names by default
使用此代码默认情况下避免使用骆驼箱名称
Use this code to avoid camel case names by default
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
来源: https://github.com/aspnet/Announcements/issues/194
这篇关于从ASP .Net Core 1.0.0-rc2-final交换为1.0.0时,JSON属性现在小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!