【发布时间】:2020-09-10 21:21:46
【问题描述】:
所以我有这个端点:
[HttpGet]
public async Task<ActionResult> Get()
{
var ext = new ApiExtensions();
List<Record> records = await ext.GetRecords();
return Ok(records);
}
这是 Record 对象:
public class Record
{
public int Id { get; set; }
public string Name { get; set; }
public string CreatedBy { get; set; }
public DateTime? DateCreated { get; set; }
public string LastModifiedBy { get; set; }
public DateTime? LastModifiedDate { get; set; }
}
在 Fiddler 或 Postman 中检查结果,我得到了我期望看到的结果。 但是这两个工具(Fiddler 和 Postman)都让我能够“看到” api 以不同格式返回的数据(正文):文本、原始、json、xml 等。那么,api 返回的到底是什么客户端?它只是原始选项卡中显示的“原始”数据吗?或者它是否以不同的格式返回相同的数据,并由客户使用正确的数据?
(我使用的是 .net core 3.1。)
谢谢。
【问题讨论】:
-
好吧,.netcore 至少从 2.2 APIs 默认返回 json,但是您可以配置 api 在启动时返回 xml。我认为 fiddler 和 postman 在您选择它时会尽力将 JSON 解析为 xml。如果你注意到它不正确的 xml,它仍然是一个 JSON 字符串。
标签: json api asp.net-core .net-core json.net