ASP.NET web api returning XML instead of JSON -
this question has answer here:
i read default, web api return json data reason when creating api, returns xml instead of json.
public class currencycontroller : apicontroller { private companydatabasecontext db = new companydatabasecontext(); // api/currency public ienumerable<currency> getcurrencies() { return db.currencies.asenumerable(); } }
i haven't modified out of ordinary i'm stumped
if modify webapiconfig follows you'll json default.
public static class webapiconfig { public static void register(httpconfiguration config) { config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); var appxmltype = config.formatters.xmlformatter.supportedmediatypes.firstordefault(t => t.mediatype == "application/xml"); config.formatters.xmlformatter.supportedmediatypes.remove(appxmltype); } }
Comments
Post a Comment