如何输出Request.CreateResponse方法的json对象?
下面的代码输出json字符串
"{RowCount:15}"
Run Code Online (Sandbox Code Playgroud)
,字符串不是json ojbect,它应该使用javscript的eval()方法转换为json对象,我希望服务器端直接返回json对象,它应该返回
{RowCount:15}
Run Code Online (Sandbox Code Playgroud)
这是一个json对象.
码
public class PagedDataAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
string jsonRowCount = "{RowCount:10}";
actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(System.Net.HttpStatusCode.OK, jsonRowCount,System.Net.Http.Formatting.JsonMediaTypeFormatter.DefaultMediaType);
}
}
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 18
而不是使用字符串,使用匿名对象:
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
var rowCount = new { RowCount = 10 };
actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(
HttpStatusCode.OK,
rowCount,
JsonMediaTypeFormatter.DefaultMediaType
);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11851 次 |
最近记录: |