should web api content negotiation from xml to jso

2019-08-10 11:40发布

I have an xml document that I want to return via a web api call.

I want to allow the user the option of the response via content negotiation.

 [HttpGet]
 public HttpResponseMessage Get()
 {
      var doc = new XmlDocument();
      doc.LoadXml("<MyExport SomeProperty='Some Value'></MyExport>");

      return Request.CreateResponse(HttpStatusCode.OK, doc);
  }

When I request this an Accept header of application/json I get:

{
  "MyExport": {
    "@SomeProperty": "Some Value"
  }
}

Is it correct that @ is included in the property name?

If so why?

0条回答
登录 后发表回答