2012-04-19 21 views
5

Tôi sử dụng RestSharp trong dự án Windows Phone 7.1 của mình.RestSharp - WP7 - Không thể deserialize XML vào danh sách

Tôi có một phản ứng trong định dạng XML ở đây: https://skydrive.live.com/redir.aspx?cid=0b39f4fbbb0489dd&resid=B39F4FBBB0489DD!139&parid=B39F4FBBB0489DD!103&authkey=!AOdT-FiS6Mw8v5Y

Tôi cố gắng để deserialize rằng đối phó với một lớp:

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

Tất cả các thuộc tính là ok trừ danh sách timhotPhotos, như bạn có thể xem tại đây :

timhotPhotos lớp:

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

Tôi đang ở đâu sai?

+0

Tôi sẽ viết một vài dòng mã để tuần tự hóa một số đối tượng XML và sau đó kiểm tra sự khác biệt giữa tệp XML được tạo và tệp XML của bạn – JonAlb

+0

cố gắng thả hàm tạo fullWall hoặc thả timhotPhotos initialization –

Trả lời

5

Bạn sẽ phải thay đổi deserializer XML mặc định cho DotNetXmlDeserializer, như thế này:

RestClient client; 

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

Sau đó, thêm thuộc tính XmlElement đến List<timhotPhotos> timhotPhotos bất động sản như thế này:

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

Bây giờ nó nên làm việc tốt!

+0

Awesome :)) bạn rất nhiều! Nó hoạt động tốt ngay bây giờ. – Mia

+0

Điều này dường như không hoạt động với 105.2.3 – user3791372

Các vấn đề liên quan