tags:

views:

60

answers:

2

Hi

I'm trying to connect to the last.fm rest services using restsharp. I can deserialize the simple data found at the example: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026

however, when i reach the images section for the artist:

<artist> 
  <name>Cher</name> 
  <mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid> 
  <url>http://www.last.fm/music/Cher&lt;/url&gt; 
  <image size="small">http://userserve-ak.last.fm/serve/34/48511693.png&lt;/image&gt; 
  <image size="medium">http://userserve-ak.last.fm/serve/64/48511693.png&lt;/image&gt; 
  <image size="large">http://userserve-ak.last.fm/serve/126/48511693.png&lt;/image&gt; 
  <image size="extralarge">http://userserve-ak.last.fm/serve/252/48511693.png&lt;/image&gt; 
  <image size="mega">http://userserve-ak.last.fm/serve/500/48511693/Cher+Tess.png&lt;/image&gt; 

i am struggling to get the library to map the data. Here is the code I have so far:

namespace *******.Core.LastFm
{
    using System.Xml.Serialization;
    using System.Collections.Generic;
    using System;

    public class image
    {
        [XmlAttribute]
        public string Size { get; set; }

        public string Value { get; set; }
    }

    public class ArtistImageCollection : List<image> { }

    public class Artist
    {
        public string Name { get; set; }
        public string Mbid { get; set; }
        public string Url { get; set; }
        [XmlArray]
        public ArtistImageCollection Image;
    }
}

this doesnt work. does anyone know how to bind this?

[i updated it to reflect nics suggestion - this doesn't work still]

i got the basis for this code from: http://www.aaronstannard.com/post/2010/06/14/How-to-Parse-a-Users-Delicious-Feed-with-RestSharp.aspx

w://

A: 

Dont you need to annotate the Size with [Attribute] and Image with [XmlArray] or something weird like that?

Nic Wise
+1  A: 

there was no get/set on Image

doh

cvista
With the default XmlDeserializer, no attributes are needed/supported so the XmlArray attribute isn't needed. The XmlAttribute one isn't needed either since it first looks for an element, then it looks for an attribute.
John Sheehan