解析值:时遇到意外字符.路径'',第1行,位置1 [英] Unexpected character encountered while parsing value: . Path '', line 1, position 1
问题描述
我已经创建了一个现成的.NET Core 2.2解决方案并运行它.如:
I've created an out of the box .NET Core 2.2 solution and run it. As in:
- 创建项目,选择"ASP.NET Core Web应用程序".
- 选择API作为项目模板.
- F5
这为我提供了默认ValuesController类中的POST处理代码:
This gives me this POST handling code in the default ValuesController class:
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
通过邮递员,我发布
{
"foo": "bar"
}
并接收
解析值:时遇到意外字符.路径",第1行,位置1.
Unexpected character encountered while parsing value: . Path '', line 1, position 1.
该错误发生在甚至未到达我的"(开箱即用)代码之前.我看到了许多有关序列化的参考,但这是在我有机会接触有效负载之前发生的.
The error occurs before even reaching "my" (out of the box) code. I see a number of references to serialization, but this is occurring before I ever get a chance to touch the payload.
缺少什么配置(可能非常简单)?
What (probably dreadfully simple) configuration is missing?
推荐答案
要在Postman中达到默认端点,请在正文中添加以下内容
To hit that default endpoint in Postman add the following in the body
"foo"
要使用以下
{
"foo": "bar"
}
您将需要一个类似这样的课程
you would need a class like this
public class MyClass
{
public string Foo { get; set; }
}
然后将帖子更改为
// POST api/values
[HttpPost]
public void Post([FromBody] MyClass value)
{
}
希望有帮助
这篇关于解析值:时遇到意外字符.路径'',第1行,位置1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!