加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-phone-7 – RestSharp – WP7 – 无法将XML反序列化为列

发布时间:2020-12-14 01:52:47 所属栏目:Windows 来源:网络整理
导读:我在 Windows Phone 7.1项目中使用RestSharp. 我在这里有XML格式的回复: https://skydrive.live.com/redir.aspx?cid=0b39f4fbbb0489ddresid=B39F4FBBB0489DD!139parid=B39F4FBBB0489DD!103authkey=!AOdT-FiS6Mw8v5Y 我试图反序化对类的响应: public class
我在 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; }
}

我哪里错了?

解决方法

您必须将默认的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>();
    }
}

现在它应该工作正常!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读