Json 从OpenBadge的POCO类序列化中省略字段
我有以下POCO课程:Json 从OpenBadge的POCO类序列化中省略字段,json,serialization,openbadge,Json,Serialization,Openbadge,我有以下POCO课程: public class BadgeClass { [Key] [ScriptIgnore()] //Internal ID not used for sending information to the OpenBadges API public int BadgeID { get; set; } //The name of the achievement. [StringLength(128)] public
public class BadgeClass
{
[Key]
[ScriptIgnore()]
//Internal ID not used for sending information to the OpenBadges API
public int BadgeID { get; set; }
//The name of the achievement.
[StringLength(128)]
public string Name { get; set; }
//A short description of the achievement.
[StringLength(128)]
public string Description { get; set; }
//URL of an image representing the achievement. Should be a square and in PNG format. Maximum size is 256kb.
public string Image { get; set; }
//URL of the criteria for earning the achievement. If the badge represents an educational achievement, consider marking
//up this up with LRMI
public string Criteria { get; set; }
//URL of the organization that issued the badge. Endpoint should be an IssuerOrganization
public string Issuer { get; set; }
//List of objects describing which educational standards this badge aligns to, if any.
//public List<AlignmentObject> Alignments { get; set; }
//List of tags that describe the type of achievement.
//public List<string> Tags { get; set; }
}
这在创建JSON文件时非常有效,但我想从序列化中省略BadgeClassID字段。我以为ScriptIgnore标记器会处理这个问题。有没有办法做到这一点?当使用Newtonsoft.Json
jsonvert.SerializeObject
进行序列化时,可以使用[JsonIgnore]
属性忽略属性
将密钥属性修改为:
[Key]
[JsonIgnore]
//Internal ID not used for sending information to the OpenBadges API
public int BadgeID { get; set; }
[Key]
[JsonIgnore]
//Internal ID not used for sending information to the OpenBadges API
public int BadgeID { get; set; }