Windows phone 7 RestSharp-WP7-无法将XML反序列化为列表
我在WindowsPhone7.1项目中使用RestSharp 我这里有一个XML格式的响应: 我尝试将该响应反序列化到一个类:Windows phone 7 RestSharp-WP7-无法将XML反序列化为列表,windows-phone-7,c#-4.0,deserialization,restsharp,Windows Phone 7,C# 4.0,Deserialization,Restsharp,我在WindowsPhone7.1项目中使用RestSharp 我这里有一个XML格式的响应: 我尝试将该响应反序列化到一个类: public class fullWall { public _user user { get; set; } public int numberOfFriend { get; set; } public int numberOfPhoto { get; set; } public List<timhotPhotos> t
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>();
}
}
我哪里错了?您必须将默认的XML反序列化程序更改为
DotNetXmlDeserializer
,如下所示:
RestClient client;
client.AddHandler("application/xml", new DotNetXmlDeserializer());
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>();
}
}
然后,将xmlement
属性添加到List-timhotPhotos
属性,如下所示:
RestClient client;
client.AddHandler("application/xml", new DotNetXmlDeserializer());
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>();
}
}
public-class-fullWall
{
公共用户{get;set;}
public int numberOfFriend{get;set;}
public int numberOfPhoto{get;set;}
[System.Xml.Serialization.xmlement()]
公共列表{get;set;}
公众全墙(
{
timhotPhotos=新列表();
}
}
现在它应该可以正常工作了 我将编写几行代码将一些对象序列化为XML,然后检查生成的XML文件和XML文件之间的差异,尝试删除fullWall构造函数或删除timhotPhotos初始化