最近我开始使用Web API。我工作正常,但我想在json中返回数据。它现在以XML格式返回记录。请指导我
答案 0 :(得分:0)
Chrome默认执行此操作,如果您只是在浏览器中尝试使用您的网址,则会返回xml。有一种方法可以告诉api只返回json,你基本上必须删除xml序列化器并且只留下json一个:
configuration.Formatters.Clear();
configuration.Formatters.Add(new JsonMediaTypeFormatter());
参考:
http://www.strathweb.com/2013/06/supporting-only-json-in-asp-net-web-api-the-right-way/