Restsharp: 无法将 XML 反序列化为列表?

创建于 2012-04-19  ·  3评论  ·  资料来源: restsharp/RestSharp

嗨,我在我的 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列表之外,所有属性都可以,如您在此处看到的:

GitHub Logo

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

我哪里错了?

最有用的评论

哦谢谢 :)

Ps:我是21岁的女孩,很高兴认识你:)

所有3条评论

在 StackOverflow 看到你的问题,在那里回复,现在将我的回复复制到这里:

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

RestClient client;

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

然后,将 XmlElement 属性添加到 ListtimhotPhotos 属性如下:

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

现在它应该可以正常工作了!

既然你接受了 StackOverflow 中的答案,我就继续关闭这个问题! ;)

哦谢谢 :)

Ps:我是21岁的女孩,很高兴认识你:)

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

nilesh-shah picture nilesh-shah  ·  6评论

stricq picture stricq  ·  6评论

Taher-Assad picture Taher-Assad  ·  5评论

weswitt picture weswitt  ·  3评论

abishekrsrikaanth picture abishekrsrikaanth  ·  3评论