Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestSharp - WP7 - Cannot deserialize XML to a list

I use RestSharp in my Windows Phone 7.1 project.

I have a response in XML format here: https://skydrive.live.com/redir.aspx?cid=0b39f4fbbb0489dd&resid=B39F4FBBB0489DD!139&parid=B39F4FBBB0489DD!103&authkey=!AOdT-FiS6Mw8v5Y

I tried to deserialize that response to a class:

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

All properties are ok except the timhotPhotos list, as you can see here:

timhotPhotos class:

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

Where am I wrong?

like image 842
Mia Avatar asked Apr 19 '12 10:04

Mia


1 Answers

You'll have to change the default XML deserializer to the DotNetXmlDeserializer, like this:

RestClient client;

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

Then, add the XmlElement attribute to the List<timhotPhotos> timhotPhotos property like this:

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

Now it should work fine!

like image 111
Pedro Lamas Avatar answered Nov 10 '22 00:11

Pedro Lamas