0

帮帮我,请接收一些 JSON 数组

如果我使用请求正文发送请求(由提琴手),如下所示:

[{"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");
    }
}

但它不起作用......

对不起,我的英语不好

4

1 回答 1

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 ...
}
于 2013-06-18T12:52:05.983 回答