[JsonProperty]在c#中用于什么?

[JsonProperty]在c#中用于什么?,c#,.net,json,C#,.net,Json,例如,为什么在下面的代码中需要它,如何进一步使用它 public class FileAttachment { [JsonProperty("fileName")] public string FileName{ get; set; } } Per:这是将此对象序列化/反序列化到json字符串或从json字符串序列化/反序列化此对象时将使用的json键 因此,如果FileName的值为file.txt,则序列化的结果为 { "fileName": "file.txt"

例如,为什么在下面的代码中需要它,如何进一步使用它

public class FileAttachment
{
    [JsonProperty("fileName")]
    public string FileName{ get; set; }
}
Per:这是将此对象序列化/反序列化到json字符串或从json字符串序列化/反序列化此对象时将使用的json键

因此,如果
FileName
的值为
file.txt
,则序列化的结果为

{
    "fileName": "file.txt"
}

或者在这种特殊情况下,它是无用的。默认的
camelCase
序列化程序将已经序列化到
fileName
,而不是
fileName