【发布时间】:2020-07-24 17:08:01
【问题描述】:
我正在尝试发送 PUT 请求,但由于某种原因我的 API 拒绝转换蛇案例属性
请求如下所示:
mercuryParserResponse 在 C# 中看起来像这样:
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class MercuryParserResponseDto
{
public string Author { get; set; }
public string Content { get; set; }
public DateTimeOffset DatePublished { get; set; }
public string Direction { get; set; }
public string Domain { get; set; }
public string Excerpt { get; set; }
public string LeadImageUrl { get; set; }
public string Url { get; set; }
[JsonProperty("word_count")]
public int WordCount { get; set; }
public string NextPageUrl { get; set; } //
public int RenderedPages { get; set; } //
public string Title { get; set; }
[JsonProperty("total_pages")]
public int TotalPages { get; set; }
}
还有我的 API 端点
[HttpPut]
public async Task<IActionResult> Put(
[FromBody]ImportArticleDto article,
CancellationToken cancellationToken = default)
{
return null;
}
但article.MercuryParserResponse.WordCount 始终是0(请注意,author 等单字属性是正确的)
为什么?为什么我的 Json 属性在这里不起作用?
【问题讨论】:
-
我试试你的代码,它的工作没有任何问题。您的 Jsonserializer 还有其他设置吗?
标签: c# json serialization .net-core webapi