C# 使用c的JSON格式#

C# 使用c的JSON格式#,c#,.net,json,C#,.net,Json,我正在尝试使用C#.net创建以下JSON对象 我创建了一个类,如下所示: public class Attachment { [JsonProperty("fallback")] public string FallBack { get; set; } [JsonProperty("color")] public string Color { get; set; } [JsonProperty("pretext")] public string

我正在尝试使用C#.net创建以下JSON对象

我创建了一个类,如下所示:

public class Attachment
{
    [JsonProperty("fallback")]
    public string FallBack { get; set; }
    [JsonProperty("color")]
    public string Color { get; set; }
    [JsonProperty("pretext")]
    public string PreText { get; set; }
    [JsonProperty("author_name")]
    public string AuthorName { get; set; }
    [JsonProperty("author_icon")]
    public string AuthorIcon { get; set; }
    [JsonProperty("title")]
    public string Title { get; set; }
    [JsonProperty("title_link")]
    public string TitleLink { get; set; }
    [JsonProperty("text")]
    public string Text { get; set; }
    [JsonProperty("image_url")]
    public string ImageUrl { get; set; }
    [JsonProperty("thumb_url")]
    public string ThumbUrl { get; set; }
    [JsonProperty("footer")]
    public string Footer { get; set; }
    [JsonProperty("footer_icon")]
    public string FooterIcon { get; set; }
    [JsonProperty("ts")]
    public long TimeStamp { get; set; }
    [JsonProperty("author_link")]
    public string AuthorLink { get; set; }
}
并尝试在类上使用JsonConvert.SerializeObject(),但它只返回如下类属性:

{
    "fallback": "Required plain-text summary of the attachment.",
    "color": "#36a64f",
    "pretext": "Pre-text",
    "author_name": "Myself",
    "author_link": "http://author.link",
    "author_icon": "http://author.icon",
    "title": "This is my great title",
    "title_link": "https://api.slack.com/",
    "text": "This is the text field",
    "image_url": "http://image.path",
    "thumb_url": "http://image.path",
    "footer": "News Article",
    "footer_icon": "http://image.path",
    "ts": 201601010000
}

关于如何首先获取“附件”部分有什么建议吗?我对JSON非常陌生,web方法似乎首先需要“attachments”数组,为什么不添加另一个类并序列化它呢

public class AttachmentsCollection
{
    [JsonProperty("attachments")]
    public Attachment[] attachments;
}
公共列表附件{get;set;}
我使用了一个列表而不是附件数组,它可以按预期工作。非常感谢。
public class AttachmentsCollection
{
    [JsonProperty("attachments")]
    public Attachment[] attachments;
}