以前使用 .net 2.0,您可以通过这种方式添加 json 内容
services.AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
要么
services.AddMvc().AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
我意识到我不能用 .net 2.1 做同样的事情。
我收到此错误:
'IServiceCollection' does not contain a definition for 'AddJsonOptions'
and the best extension method overload 'MvcJsonMvcBuilderExtensions.AddJsonOptions(IMvcBuilder, Action<MvcJsonOptions>)'
requires a receiver of type 'IMvcBuilder
有人有解决方案吗?
最佳答案
采用
services.AddMvc().AddJsonOptions(...)
来配置它。
以上扩展方法可以在
Microsoft.AspNetCore.Mvc.Formatters.JsonVersion 2.1.0.0
中找到。要么直接包含这个包,要么添加这两个 Microsoft.AspNetCore.App
/Microsoft.AspNetCore.All
之一。关于.net - 服务 AddJsonOptions .net 核心 2.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51064314/