Asp.net core Can';t将对象列表发布到web api
我在这里做错了什么(我使用的是.net core 3.1): 对象: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.
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