在没有特定Json服务的Program.cs中:
builder.Services.AddControllers(options =>
{
options.ReturnHttpNotAcceptable = true;
}).AddXmlDataContractSerializerFormatters();
Postman Json回应(我更喜欢的一个):
{
"id": 1,
"name": "Central Park",
"description": "The most visited urban park in the United States."
}
在具有特定Json服务的Program.cs中:
builder.Services.AddControllers(options =>
{
options.ReturnHttpNotAcceptable = true;
}).AddXmlDataContractSerializerFormatters().AddNewtonsoftJson();
Postman 的React,不会是杰森(一个我真的鄙视):
<PointsOfInterestDto xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/CityInfo.API.Models"><Description>The most visited urban park in the United States.</Description><Id>1</Id><Name>Central Park</Name></PointsOfInterestDto>
如何实现Json响应?
1条答案
按热度按时间iugsix8n1#
AddXmlDataContractSerializerFormatters()
是个问题...变更为: