我在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>();
}
}
除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; }
}
我哪里错了?
答案 0 :(得分:5)
您必须将默认的XML反序列化器更改为DotNetXmlDeserializer
,如下所示:
RestClient client;
client.AddHandler("application/xml", new DotNetXmlDeserializer());
然后,将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>();
}
}
现在它应该可以正常工作!