Restsharp: Cannot deserialize XML to a list?

Created on 19 Apr 2012  ·  3Comments  ·  Source: restsharp/RestSharp

Hi, 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:

GitHub Logo

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?

Most helpful comment

Oh, thanks :)

Ps: I'm 21 years-old girl, nice to meet you :)

All 3 comments

Saw your question in StackOverflow, replyed there, now copying my reply to here:

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 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!

And since you accepted the answer in StackOverflow, I'll just go ahead and close this issue! ;)

Oh, thanks :)

Ps: I'm 21 years-old girl, nice to meet you :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

instriker picture instriker  ·  7Comments

Taher-Assad picture Taher-Assad  ·  5Comments

captnrob picture captnrob  ·  3Comments

wojciechrak picture wojciechrak  ·  3Comments

qJake picture qJake  ·  7Comments