Pregunta

Estoy tratando de tomar una fuente RSS y deserializarlo en una lista de objetos RSSentry.

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

Esto llena todo en excepto contenido que contiene CDATA

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

Estoy abierto a usar algo que no sea RestSharp, pero lo estaba probando por esto con la esperanza de que fuera una solución agradable.

Actualmente, cualquier campo con CDATA se devuelve como NULL.

¿Fue útil?

Solución

El problema fue que leí a través del XML en la fuente RSS y nombré las variables en el contenido de la clase de elementos.El elemento de artículo real en la fuente RSS fue el contenido: codificado.

Cambio de esta variable para codificada, lo arregló, completamente mi propia falla.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top