AddJsonOptions
메서드 변경 사항문제: ASP.NET Core 3.0으로 업그레이드한 후 AddJsonOptions
메서드가 사라지고 종속성을 다시 설치해도 문제가 해결되지 않았습니다.
정답:
배경:
ASP.NET Core 3.0은 기본 JSON 직렬화 메커니즘을 변경합니다. Json.NET은 성능에 초점을 맞춘 새로운 JSON API로 대체되었습니다.
Json.NET 사용:
Json.NET 호환성이 필요한 경우 다음 단계를 따르세요.
Microsoft.AspNetCore.Mvc.NewtonsoftJson
NuGet 패키지를 설치합니다. Startup
클래스의 ConfigureServices
메서드에서 다음 코드를 사용하여 MVC를 구성합니다. <code class="language-csharp">services.AddControllers() .AddNewtonsoftJson();</code>
구성 옵션:
오버로드된 메서드를 사용하여 Json.NET 옵션을 추가로 구성할 수 있습니다.
<code class="language-csharp">services.AddControllers() .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });</code>
위 내용은 ASP.NET Core 3.0: 'AddJsonOptions'는 어디로 갔나요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!