我正在尝试使用RSS Feed并将其反序列化为RSSentry对象的列表。

var Client = new RestClient("url here");
Request = new RestRequest { RequestFormat DataFormat.Xml };
var response = Client.Execute<Channel>(Request);
return response.Data.Item;
.

这将填充除附录中包含cdata 的内容中的所有内容

channel.cs

 public class Channel
 {
    public string Title { get; set; }
    public string Link { get; set; }
    public string AtomLink { get; set; }
    public string Description { get; set; }
    public DateTime LastBuildDate { get; set; }
    public string Generator { get; set; }
    public string Language { get; set; }
    public string UpdatePeriod { get; set; }
    public int UpdateFrequency { get; set; }
    public RssItems Item { get; set; }
}
.

项.cs

public class Item 
{
        public string Title { get; set; }
        public string Link { get; set; }
        public string Comments { get; set; }
        public DateTime PubDate { get; set; }
        public string Creator { get; set; }
        public string Category { get; set; }
        public string Description { get; set; }
        public string Content { get; set; }
        public string Guid { get; set; }
        public string CommentRss { get; set; }
        public int SlashComments { get; set; }
  }
.

我很开放使用reasharp以外的东西,但我正在尝试这一点,希望这将是一个很好的解决方案。

当前使用cdata的任何字段都返回为null。

有帮助吗?

解决方案

问题是我通过RSS Feed中的XML读取,我将变量命名为项目类内容。RSS Feed中的实际项目元素是内容:编码。

将此变量更改为编码固定它,完全是我自己的故障。

public class Item 
{
        public string Title { get; set; }
        public string Link { get; set; }
        public string Comments { get; set; }
        public DateTime PubDate { get; set; }
        public string Creator { get; set; }
        public string Category { get; set; }
        public string Description { get; set; }
        public string Encoded { get; set; }
        public string Guid { get; set; }
        public string CommentRss { get; set; }
        public int SlashComments { get; set; }
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top