星空网 > 软件开发 > ASP.net

Asp.net Core WebApi 返回JSON自动驼峰格式化问题

从今天开始,正式进入Asp.net Core的开发,估计最近一段时间会经常写博客了,记录学些Asp.net Core中遇到的各种坑。

第一个问题:通过core编写的webapi,默认返回的json会自动格式化为驼峰样式,并没有按照具体的类名来返回,如何让其按照类名返回呢?

public void ConfigureServices(IServiceCollection services)    {      // Add framework services.      services.AddApplicationInsightsTelemetry(Configuration);      services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); ;    }

在Startup.cs全局配置类里面,加入json配置选项即可解决,同时不要忘记引用:using Newtonsoft.Json.Serialization;

{"Statuz":0,"ErrorMsg":"获取成功","Data":[{"Name":"xxx","MobilePhone":"15xxxx81xxx","Sex":"0","Score":-102},{"Name":"xxxxx","MobilePhone":"15xxxxx1xx1","Sex":"0","Score":-102}]}

返回值清爽了。

 

参考文章:http://www.cnblogs.com/zhong-ken/p/6062782.html

 




原标题:Asp.net Core WebApi 返回JSON自动驼峰格式化问题

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流