【发布时间】:2015-10-09 06:35:53
【问题描述】:
我需要将一个额外的 JSON 对象附加到由 Web API 方法生成的 JSON 响应中。例如:
我现在的代码:
[Route("api/getcomnts")]
public IHttpActionResult GetCommentsForActivity(string actid)
{
List<Comment> cmntList = CC.GetAllComments(actid);
return Ok(cmntList);
}
如果成功检索到 cmets,我想发送:
“状态”:“成功”
连同它已经作为 JSON 数组发送的 cmets 列表。
或
“状态”:“失败”
如果 cmets 列表为 EMPTY。是否可以将这个名为 JSON 的额外 JSON 对象附加到我已经存在的方法中?
这将使我的客户端 Android 和 iOS 应用程序非常方便:)
编辑
或者对于这样的场景:
[HttpGet]
[Route("api/registeruser")]
public IHttpActionResult RegisterUser(string name, string email, string password)
{
int stat = opl.ConfirmSignup(name, email, password);
string status = "";
if (stat == 0)
{
status = "fail";
}
else
{
status = "success";
}
return Ok(status);
}
【问题讨论】:
标签: asp.net json azure asp.net-web-api azure-mobile-services