22

我想知道 System.Text.Json 中 Newtonsoft.Json's / Json.Net'sJsonProperty字段的等价物是什么。

例子:

using Newtonsoft.Json;

public class Example
{
    [JsonProperty("test2")]
    public string Test { get; set; }
}

参考:

4

1 回答 1

32

以防万一,其他任何人都会跌倒。该属性被重命名为JsonPropertyName并来自System.Text.Json.SerializationnugetSystem.Text.Json包。

例子:

using System.Text.Json.Serialization;

public class Example
{
    [JsonPropertyName("test2")]
    public string Test { get; set; }
}

参考:

于 2019-10-20T17:46:32.253 回答