解析值:时遇到意外字符.路径'',第1行,位置1 [英] Unexpected character encountered while parsing value: . Path '', line 1, position 1

查看:978
本文介绍了解析值:时遇到意外字符.路径'',第1行,位置1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个现成的.NET Core 2.2解决方案并运行它.如:

I've created an out of the box .NET Core 2.2 solution and run it. As in:

  1. 创建项目,选择"ASP.NET Core Web应用程序".
  2. 选择API作为项目模板.
  3. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆