-1
如何在ASP.NET Web API返回给客户端之前编辑和更改返回的JSON。 例如:在ASP.Net Web API中自定义返回的JSON数据
public HttpResponseMessage GetCustomerById(int customerId)
{
Customer customer = DAL.GetCustomer(123);
if (customer == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound, "Could not find customer " + customerId.ToString());
}
else
{
return Request.CreateResponse(HttpStatusCode.OK, customer);
**// Here I like to edit the JSON before I return it**
}
}
您可以创建自定义序列并使用它的标准一个 –
究竟是你想改变什么?客户对象? – mezmi
是的。假设我想以特定格式返回日期 - 特殊格式的Customer.SomeDate属性(UTC) – user3237706