更新时间:2023-09-17 11:41:22
ASP.NET Core 3 使用 System.Text.Json
而不是 Newtonsoft.Json
(又名 JSON).NET) 来处理 JSON.JSON.NET 支持从字符串解析为十进制,但 System.Text.Json
不支持.如文档:
ASP.NET Core 3 uses System.Text.Json
instead of Newtonsoft.Json
(aka JSON.NET) for handling JSON. JSON.NET supports parsing from a string into a decimal, but System.Text.Json
does not. The easiest thing to do at this stage is to switch back to using JSON.NET, as described in the docs:
更新 Startup.ConfigureServices
以调用 AddNewtonsoftJson
.
- Add a package reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson.
Update
Startup.ConfigureServices
to callAddNewtonsoftJson
.
services.AddMvc()
.AddNewtonsoftJson();
将十进制数作为 JSON 数字传递会更正确,但很明显这不适合您.
It would be more correct to pass the decimal as a JSON number, but it's clear that's not going to be an option for you.