请帮助我,请收到一些JSON数组
如果我向请求主体发送请求(由Fiddler提供),请执行以下操作:
[{“name”:“Homerius”,“tonumber”:“155555”,“fromnumber”:“166666”,“text”:“&& ??!”},{“name”:“ Stone“,”tonumber“:”9654999“,”fromnumber“:”999666“,”text“:”h9miii99!“}]
我怎样才能在控制器中收到它?
我尝试做这样的事情:
public HttpResponseMessage Post(JObject[] smspackage)
{
List<MySMS> smses = smspackage.ToList<MySMS>();
try
{
SMS_Repository.Add(smses);
return Request.CreateResponse<MySMS>(HttpStatusCode.Created, smses);
}
catch (Exception)
{
return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "error");
}
}
但它不起作用......
抱歉我的英文不好
答案 0 :(得分:0)
为什么不使用:
public HttpResponseMessage Post(List<MySMS> smses)
{
try
{
SMS_Repository.Add(smses);
return Request.CreateResponse<List<MySMS>>(HttpStatusCode.Created, smses);
}
catch (Exception)
{
return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "error");
}
}
或者:
public HttpResponseMessage Post(JArray smspackage)
{
List<MySMS> smses = smspackage.ToObject<List<MySMS>>();
... snip ...
}