2 回答
TA貢獻(xiàn)1799條經(jīng)驗 獲得超9個贊
在 C# 中,@變量的前綴用于允許您使用保留字,例如@class. 所以它會被有效地忽略。要控制序列化的屬性名稱,您需要將JsonProperty屬性添加到模型中:
public class PotentialAction
{
[JsonProperty("@context")]
public string @context { get; set; }
[JsonProperty("@type")]
public string @type { get; set; }
public string name { get; set; }
public IList<string> target { get; set; } = new List<string>();
}
TA貢獻(xiàn)1777條經(jīng)驗 獲得超3個贊
您可以使用一些屬性來定義字段名稱應(yīng)該是什么。
https://www.newtonsoft.com/json/help/html/SerializationAttributes.htm
你會像這樣使用它: [JsonProperty(PropertyName = "@context")]
Public string context { get; set ; }
- 2 回答
- 0 關(guān)注
- 324 瀏覽
添加回答
舉報
