2012-04-19 29 views
5

Utilizo RestSharp en mi proyecto Windows Phone 7.1.RestSharp - WP7 - No se puede deserializar XML a una lista

tengo una respuesta en formato XML aquí: https://skydrive.live.com/redir.aspx?cid=0b39f4fbbb0489dd&resid=B39F4FBBB0489DD!139&parid=B39F4FBBB0489DD!103&authkey=!AOdT-FiS6Mw8v5Y

Me trataron de deserializar que la respuesta a una clase:

public class fullWall 
{ 
    public _user user { get; set; } 
    public int numberOfFriend { get; set; } 
    public int numberOfPhoto { get; set; } 
    public List<timhotPhotos> timhotPhotos { get; set; } 
    public fullWall() 
    { 
     timhotPhotos = new List<timhotPhotos>(); 
    } 
} 

Todas las propiedades están bien, excepto la lista timhotPhotos, como se puede ver aquí : clase

timhotPhotos:

public class timhotPhotos 
{ 
    public string id { get; set; } 
    public string title { get; set; } 
    public string description { get; set; } 
    public string url { get; set; } 
    public double width { get; set; } 
    public double height { get; set; } 
    public DateTime createdDate { get; set; } 
    public _user user { get; set; } 
    public int numOfComment { get; set; } 
    public int numOfRate { get; set; } 
    public int numOfView { get; set; } 
    public bool rated { get; set; } 
} 

¿Dónde estoy equivocado?

+0

Escribiría un par de líneas de código para serializar algunos objetos en XML y luego verificaría las diferencias entre el archivo XML generado y su archivo XML – JonAlb

+0

intente soltar el constructor FullWall o soltar la inicialización de timhotPhotos –

Respuesta

5

Vas a tener que cambiar el deserializer XML por defecto a la DotNetXmlDeserializer, así:

RestClient client; 

client.AddHandler("application/xml", new DotNetXmlDeserializer()); 

A continuación, añadir el atributo XmlElement a la propiedad List<timhotPhotos> timhotPhotos así:

public class fullWall 
{ 
    public _user user { get; set; } 
    public int numberOfFriend { get; set; } 
    public int numberOfPhoto { get; set; } 
    [System.Xml.Serialization.XmlElement()] 
    public List<timhotPhotos> timhotPhotos { get; set; } 
    public fullWall() 
    { 
     timhotPhotos = new List<timhotPhotos>(); 
    } 
} 

Ahora debería funcionar bien!

+0

Awesome :)) gracias ¡Tú mucho! Funciona bien ahora. – Mia

+0

Esto no parece funcionar con 105.2.3 – user3791372

Cuestiones relacionadas