- Solution
- If you return a serializable object, WebAPI will automatically send JSON or XML based on the Accept header that your client sends.
- Code
public class DemoController : ApiController
{
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}
public List< User> Post()
{
List< User> lUser = new List< User>()
{
new User(){ Name = "Lyndon", Age = 30 },
new User(){ Name = "Daisy", Age = 27 },
};
return lUser;
}
}
- XML
- Harders 加入 Accept: application/xml
- Ref:
- https://stackoverflow.com/questions/11662028/webapi-to-return-xml
沒有留言:
張貼留言