How do I specify if I want JSON or XML in ASP.NET Web API?

后端 未结 3 1837
既然无缘
既然无缘 2021-01-04 11:09

I\'ve written two ASP.NET Web API applications this week which both contain a single simple controller; I\'ve tweaked each to get them to work, include exceptions, and so on

3条回答
  •  离开以前
    2021-01-04 11:25

    To restrict output to only one formatter, try the instructions here:

    http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#removing_the_json_or_xml_formatter

    On a related note, the following link covers how ASP.NET Web API decides what output format to use depending on the HTTP request sent to it, i.e. how it chooses JSON over XML:

    http://www.asp.net/web-api/overview/formats-and-model-binding/content-negotiation

    It may be useful if you want to still support both formats, but need to ensure your own client code always receives JSON back.

提交回复
热议问题