从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

查看:53
本文介绍了从ASP .Net Core 1.0.0-rc2-final交换为1.0.0时,JSON属性现在小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将项目从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆