Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core Can';t将对象列表发布到web api_Asp.net Core_Asp.net Web Api - Fatal编程技术网

Asp.net core Can';t将对象列表发布到web api

Asp.net core Can';t将对象列表发布到web api,asp.net-core,asp.net-web-api,Asp.net Core,Asp.net Web Api,我在这里做错了什么(我使用的是.net core 3.1): 对象: public class Member { public int NUM {get;set;} } 行动后 [HttpPost] public async Task<IActionResult> Post([FromBody] IEnumerable<Member> members) { "type": "https://tools.

我在这里做错了什么(我使用的是.net core 3.1):

对象:

   public class Member
    {
        public int NUM {get;set;}
    }
行动后

     [HttpPost]
     public async Task<IActionResult> Post([FromBody] IEnumerable<Member> members)
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "|fc86d5d0-498dec466e59f3c5.",
    "errors": {
        "$": [
            "The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[TRS.Gemini.MemberApi.Controllers.Member]. Path: $ | LineNumber: 0 | BytePositionInLine: 1."
        ]
    }
}
邮递员发来的错误

     [HttpPost]
     public async Task<IActionResult> Post([FromBody] IEnumerable<Member> members)
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "|fc86d5d0-498dec466e59f3c5.",
    "errors": {
        "$": [
            "The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[TRS.Gemini.MemberApi.Controllers.Member]. Path: $ | LineNumber: 0 | BytePositionInLine: 1."
        ]
    }
}

我试着发布一个对象而不是一个集合,效果很好。当然,最后的对象要复杂得多,但我想从简单开始。

对于您定义的对象,有效的JSON输入应该是:

[
    {"NUM": 5},
    {"NUM": 4}
]
注意缺少{}括号

您指定的负载也是无效的JSON