Domanda

Sto cercando di prendere un feed RSS e lo deserializzarlo in un elenco di oggetti RSSentry.

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

Ciò riempie tutto in eccetto il contenuto che contiene CDATA

canale.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; }
}
.

Item.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; }
  }
.

Sono aperto a usare qualcosa di diverso da RestSharp, ma lo stavo provando per questo sperando che sarebbe una bella soluzione facile.

Attualmente qualsiasi campo con CDATA viene restituito come NULL.

È stato utile?

Soluzione

Il problema è stato che ho letto attraverso l'XML nel feed RSS e ho nominato le variabili nel contenuto della classe elementi.L'elemento oggetto effettivo nel feed RSS è stato il contenuto: codificato.

Modifica di questa variabile per codificata fissata, completamente il mio errore.

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; }
}
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top