在 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/