c# - ASP.NET Core 3.0 [FromBody] 字符串内容返回 "The JSON value could not be converted to System.String."

标签 c# json asp.net-core asp.net-core-mvc asp.net-core-3.0

在 ASP.NET Core 3.0 中的 ApiController 上使用 [FromBody] 字符串内容返回验证错误:

{"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
 "title":"One or more validation errors occurred.",
 "status":400,
 "traceId":"|9dd96d96-4e64bafba4ba0245.",
 "errors":{"$":["The JSON value could not be converted to System.String. Path: $ | LineNumber: 0 | BytePositionInLine: 1."]}}

当客户端发布内容类型为application/json的数据时

如何在 .NET Core 3.0 的 api Controller 中获取原始 json 数据作为字符串?客户端无需更新其内容类型?

最佳答案

不确定这是否有帮助,但我认为他们对 .net core 3.0 Newtonsoft.JSON 包进行了一些更改,因此您可以试试这个

安装 Microsoft.AspNetCore.Mvc.NewtonsoftJson 包。

在你的 startup.cs 添加

services.AddControllers().AddNewtonsoftJson();

关于c# - ASP.NET Core 3.0 [FromBody] 字符串内容返回 "The JSON value could not be converted to System.String.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58150652/

相关文章:

c# - ado.net并发冲突如何解决

c# - 如何更新 ComboBox

Java Jackson 将 JSON 序列化为 HashTable

php - 如何从Android应用程序的mysql数据库中检索数据

azure - 是否有适当的 Core 3.0 API 中间件来将 Azure AD B2C 用户连接到我的数据库帐户?

c# - 在 IIS 7 中托管 Asp.Net Core

c# - 直接添加引用和通过Nuget添加包有什么区别

json - 如何在 Swift 中解码 HTML 实体?

asp.net-core - 我想使用两个 DbContext asp.net core

c# - System.Management.Automation 与 .NET Core 3.1 不兼容