1. <small id='g6plb'></small><noframes id='g6plb'>

      2. <legend id='g6plb'><style id='g6plb'><dir id='g6plb'><q id='g6plb'></q></dir></style></legend>
          <bdo id='g6plb'></bdo><ul id='g6plb'></ul>
      3. <i id='g6plb'><tr id='g6plb'><dt id='g6plb'><q id='g6plb'><span id='g6plb'><b id='g6plb'><form id='g6plb'><ins id='g6plb'></ins><ul id='g6plb'></ul><sub id='g6plb'></sub></form><legend id='g6plb'></legend><bdo id='g6plb'><pre id='g6plb'><center id='g6plb'></center></pre></bdo></b><th id='g6plb'></th></span></q></dt></tr></i><div id='g6plb'><tfoot id='g6plb'></tfoot><dl id='g6plb'><fieldset id='g6plb'></fieldset></dl></div>
        <tfoot id='g6plb'></tfoot>
      4. .Net Core 3.0 中的 IMvcBuilder AddJsonOptions 去了哪里?

        时间:2023-08-23

        <small id='GeHY2'></small><noframes id='GeHY2'>

            <tbody id='GeHY2'></tbody>

        1. <tfoot id='GeHY2'></tfoot>
              <bdo id='GeHY2'></bdo><ul id='GeHY2'></ul>
                <legend id='GeHY2'><style id='GeHY2'><dir id='GeHY2'><q id='GeHY2'></q></dir></style></legend>

                1. <i id='GeHY2'><tr id='GeHY2'><dt id='GeHY2'><q id='GeHY2'><span id='GeHY2'><b id='GeHY2'><form id='GeHY2'><ins id='GeHY2'></ins><ul id='GeHY2'></ul><sub id='GeHY2'></sub></form><legend id='GeHY2'></legend><bdo id='GeHY2'><pre id='GeHY2'><center id='GeHY2'></center></pre></bdo></b><th id='GeHY2'></th></span></q></dt></tr></i><div id='GeHY2'><tfoot id='GeHY2'></tfoot><dl id='GeHY2'><fieldset id='GeHY2'></fieldset></dl></div>
                  本文介绍了.Net Core 3.0 中的 IMvcBuilder AddJsonOptions 去了哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我刚刚将我的 ASP Web API 项目从 .Net core 2.0 升级到 3.0.我正在使用

                  I've just upgraded my ASP web API project from .Net core 2.0 to 3.0. I was using

                       services.AddMvc()
                               .AddJsonOptions(options =>options.SerializerSettings.ContractResolver 
                                                         = new DefaultContractResolver());
                  

                  以前是为了确保序列化 JSON 的小写.

                  previously to ensure lower-casing of the serialized JSON.

                  升级到 3.0 后出现此错误:

                  After the upgrade to 3.0 I get this error:

                  错误 CS1061 'IMvcBuilder' 不包含'AddJsonOptions' 并且没有可访问的扩展方法 'AddJsonOptions'可以找到接受IMvcBuilder"类型的第一个参数(是您缺少 using 指令或程序集引用?)

                  Error CS1061 'IMvcBuilder' does not contain a definition for 'AddJsonOptions' and no accessible extension method 'AddJsonOptions' accepting a first argument of type 'IMvcBuilder' could be found (are you missing a using directive or an assembly reference?)

                  根据 AddJsonOptions for MvcJsonOptions in Asp.Net Core 2.2 AddJsonOptions 扩展方法由 Microsoft.AspNetCore.Mvc.Formatters.Json nuget 包提供.我已经尝试安装/重新安装它,但仍然无法解决该方法.有趣的是,即使我添加了 Json nuget 包,当我尝试添加 using 语句时,智能感知仅显示 Microsoft.AspNetCore.Mvc.Formatters.Xml.

                  According to AddJsonOptions for MvcJsonOptions in Asp.Net Core 2.2 the AddJsonOptions extension method is/was provided by the Microsoft.AspNetCore.Mvc.Formatters.Json nuget package. I have tried installing/reinstalling this but still can't resolve the method. Interestingly, intellisense only shows Microsoft.AspNetCore.Mvc.Formatters.Xml when I try to add the using statement even though I added the Json nuget package.

                  有什么想法吗?AddJsonOptions 的 noreferrer">文档 仅适用于 .Net 2.2,因此该方法在 3.0 中可能已被弃用,而支持其他一些配置机制?

                  Any ideas what is going on? The documentation for AddJsonOptions only goes up to .Net 2.2 so perhaps the method has been deprecated in 3.0 in favor of some other configuration mechanism?

                  推荐答案

                  作为 ASP.NET Core 3.0 的一部分,团队默认不再包含 Json.NET.您可以在 关于 Microsoft.AspNetCore.App 的重大更改的公告.

                  As part of ASP.NET Core 3.0, the team moved away from including Json.NET by default. You can read more about that in general in the announcement on breaking changes to Microsoft.AspNetCore.App.

                  ASP.NET Core 3.0 和 .NET Core 3.0 包含不同的 JSON API,而不是 Json.NET,它更加注重性能.您可以在关于.NET Core 3.0 中 JSON 的未来"的公告中了解更多信息.

                  Instead of Json.NET, ASP.NET Core 3.0 and .NET Core 3.0 include a different JSON API that focuses a bit more on performance. You can learn about that more in the announcement about "The future of JSON in .NET Core 3.0".

                  ASP.NET Core 的新模板将不再与 Json.NET 捆绑,但您可以轻松地重新配置项目以使用它而不是新的 JSON 库.这对于与旧项目的兼容性都很重要,也因为新库不应该完全替代,因此您不会在那里看到完整的功能集.

                  The new templates for ASP.NET Core will no longer bundle with Json.NET but you can easily reconfigure the project to use it instead of the new JSON library. This is important for both compatibility with older projects and also because the new library is not supposed to be a full replacement, so you won't see the full feature set there.

                  为了使用 Json.NET 重新配置您的 ASP.NET Core 3.0 项目,您需要添加对 Microsoft.AspNetCore.Mvc.NewtonsoftJson 的 NuGet 引用,该包包含所有必要的位.然后,在 Startup 的 ConfigureServices 中,您需要像这样配置 MVC:

                  In order to reconfigure your ASP.NET Core 3.0 project with Json.NET, you will need to add a NuGet reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson, which is the package that includes all the necessary bits. Then, in the Startup’s ConfigureServices, you will need to configure MVC like this:

                  services.AddControllers()
                      .AddNewtonsoftJson();
                  

                  这会设置 MVC 控制器并将其配置为使用 Json.NET 而不是新的 API.除了控制器,您还可以使用不同的 MVC 重载(例如,用于具有视图的控制器或 Razor 页面).AddNewtonsoftJson 方法有一个重载,允许您像在 ASP.NET Core 2.x 中使用 AddJsonOptions 一样配置 Json.NET 选项.

                  This sets up MVC controllers and configures it to use Json.NET instead of that new API. Instead of controllers, you can also use a different MVC overload (e.g. for controllers with views, or Razor pages). That AddNewtonsoftJson method has an overload that allows you to configure the Json.NET options like you were used to with AddJsonOptions in ASP.NET Core 2.x.

                  services.AddControllers()
                      .AddNewtonsoftJson(options =>
                      {
                          options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                      });
                  

                  这篇关于.Net Core 3.0 中的 IMvcBuilder AddJsonOptions 去了哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:行分隔的 json 序列化和反序列化 下一篇:检测反序列化对象是否缺少 Json.NET 中 JsonConvert

                  相关文章

                  最新文章

                2. <tfoot id='bmuE5'></tfoot>
                  • <bdo id='bmuE5'></bdo><ul id='bmuE5'></ul>
                  <legend id='bmuE5'><style id='bmuE5'><dir id='bmuE5'><q id='bmuE5'></q></dir></style></legend>
                    <i id='bmuE5'><tr id='bmuE5'><dt id='bmuE5'><q id='bmuE5'><span id='bmuE5'><b id='bmuE5'><form id='bmuE5'><ins id='bmuE5'></ins><ul id='bmuE5'></ul><sub id='bmuE5'></sub></form><legend id='bmuE5'></legend><bdo id='bmuE5'><pre id='bmuE5'><center id='bmuE5'></center></pre></bdo></b><th id='bmuE5'></th></span></q></dt></tr></i><div id='bmuE5'><tfoot id='bmuE5'></tfoot><dl id='bmuE5'><fieldset id='bmuE5'></fieldset></dl></div>

                    1. <small id='bmuE5'></small><noframes id='bmuE5'>