RestSharp - WP7 - 无法将XML反序列化为列表

Mia*_*Mia 5 windows-phone-7 restsharp deserialization c#-4.0

我在Windows Phone 7.1项目中使用RestSharp.

我有一个XML格式的响应位置: https://skydrive.live.com/redir.aspx?cid=0b39f4fbbb0489dd&resid=B39F4FBBB0489DD!139&parid=B39F4FBBB0489DD!103&authkey=!AOdT-FiS6Mw8v5Y

我试图反序化对类的响应:

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>();
    }
}
Run Code Online (Sandbox Code Playgroud)

timhotPhotos列表外,所有属性都可以,您可以在此处看到:

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; }
}
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

Ped*_*mas 5

您必须将默认的XML反序列化器更改为DotNetXmlDeserializer,如下所示:

RestClient client;

client.AddHandler("application/xml", new DotNetXmlDeserializer());
Run Code Online (Sandbox Code Playgroud)

然后,将XmlElement属性添加到属性,List<timhotPhotos> timhotPhotos如下所示:

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>();
    }
}
Run Code Online (Sandbox Code Playgroud)

现在它应该工作正常!