The JSON value could not be converted to System.Int32

前端 未结 6 1857
南方客
南方客 2020-12-03 02:39

I want to send data of object to my Web API. The API accepts a parameter of class, which properties are type of int and string.

This is my class:

publi         


        
6条回答
  •  孤街浪徒
    2020-12-03 03:19

    In .NET CORE 3.X the serialize/deserialize process is done using System.Text.Json not Newtonsoft Json. Edward's answer did not work entirely for me:

    1. Installing from Nuget Manager Microsoft.AspNetCore.Mvc.NewtonsoftJson won't make step 2 to compile.
    2. Yes, add in Startup services.AddControllers().AddNewtonsoftJson(); - you will receive an error, AddNewtonsoftJson() not recognized.

    At least this happened to me.

    As a fix, uninstall what you've installed at step 1. In package manager console, run: Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson -Version 3.0.0-preview8.19405.7 . This worked for me.

提交回复
热议问题