JsonResult(object) causes “The collection type 'Newtonsoft.Json.Linq.JToken' is not supported.”

前端 未结 3 1209
一向
一向 2021-02-03 21:34

I upgraded an existing ASP.NET Core 2.2 project to 3.0. I have a method that returns JSON which worked in 2.2, but in 3.0, it causes \"The collection type \'Newtonsoft.Json.Linq

3条回答
  •  走了就别回头了
    2021-02-03 22:18

    @sabiland answer helped me, small changes

    1. added in .csproj reference to NewtonsoftJson, as below

    < PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />

    1. adde in Startup.cs, in method ConfigureServices, AddMvcCore

      services.AddMvcCore()
              .AddNewtonsoftJson();
      

提交回复
热议问题