【发布时间】:2017-08-24 00:09:44
【问题描述】:
下面是我的 API。
public HttpResponseMessage Delete(IEnumerable<int> customerIds)
{
//api stuff
}
但是当这个 API 被点击时,我将 customerIds 设为 null。
这就是我通过 Postman 调用 API 的方式。
{
"customerIds" : [69,50]
}
Content-Type = application/json
但是,如果我按如下方式更新 API,则会捕获值。
public HttpResponseMessage Delete(CustomerTO customerIds)
{
//api stuff
}
public class CustomerTO
{
public IEnumerable<int> CustomerIds
}
如果我这样做,我认为这是一个开销。
非常感谢任何帮助/建议。
【问题讨论】:
-
您传入的对象具有名为
customerIds的属性。你需要传入一个整数数组,[59,60]。 -
用
public IEnumerable<int> CustomerIds替换CustomerTO customerIds -
或在您的 json 中将
"customerIds" : [69,50]替换为 "customerIds" : {"cutomerIds": [69,50]} -
@Alex:用
IEnumerable<int> CustomerIds替换CustomerTO customerIds只会给你原件,不是吗?或者您是否正在考虑替换其他地方(不确定在哪里可以使用public关键字,所以试图猜测您的意思)。另外,我什至不确定您对第二条评论的想法。这将如何帮助更简单的代码工作?这不会让事情变得更糟吗? -
@Chris,我的错。没有仔细阅读问题。 @Kgn-web 是
HTTPDELETE的请求吗?
标签: c# json asp.net-web-api postman