排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

这个问题如果不是被人问我我还真不知道有这么一个坑
通常我们需要在WebApi里返回json格式的数据,可以通过HttpResponseMessage的方式来处理,因为WebApi默认返回的是XML格式
在FrameWork里的WebApi确实可以没问题,但是在Net Core里的WebApi
HttpResponseMessage处理返回json数据时得到一堆未知的东西
解决方法:
安装 nuget 包 Microsoft.AspNetCore.Mvc.WebApiCompatShim
在 Startup -> ConfigureServices 中,在 AddMvc() 之后添加 AddWebApiConventions() 即可:代码如下
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddMvc().AddWebApiConventions(); }
然后看看效果:
评价