English 中文(简体)
Using restsharp in c# to consume last.fm services
原标题:
  • 时间:2010-07-26 13:10:30
  •  标签:
  • restsharp

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=xxxxxxxxxxxxxxxxxxxxxxx

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</url> 
  <image size="small">http://userserve-ak.last.fm/serve/34/48511693.png</image> 
  <image size="medium">http://userserve-ak.last.fm/serve/64/48511693.png</image> 
  <image size="large">http://userserve-ak.last.fm/serve/126/48511693.png</image> 
  <image size="extralarge">http://userserve-ak.last.fm/serve/252/48511693.png</image> 
  <image size="mega">http://userserve-ak.last.fm/serve/500/48511693/Cher+Tess.png</image> 

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://

最佳回答

there was no get/set on Image

doh

问题回答

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





相关问题
How to use RestSharp with OAuth?

I am confused which factory OAuth1Authenticator factory method should I use. I think I should get a consumer secret token (can I get it with RestSharp?), then use OAuth1Authenticator.ForRequestToken, ...

Refreshing in RestSharp for Windows Phone

I implemented RestSharp succesfully in my WP7 application, but one issue remains: When I load resources from the server (for example a GET request on http://localhost:8080/cars), the first time the ...

Deserializing XML CDATA into string variable with RestSharp

I m trying to take an RSS feed and deserialize it into a list of rssEntry objects. var Client = new RestClient("url here"); Request = new RestRequest { RequestFormat DataFormat.Xml }; var response = ...

error while adding restsharp refernce

I have a problem adding the reference of REstsharp.dll. It says: "Reference cannot be added to d:Vinay sreeRestSharp-101.2RestSharp.dll because it was not built using the Windows Phone runtime. ...

How to add text to request body in RestSharp

I m trying to use RestSharp to consume a web service. So far everything s gone very well (cheers to John Sheehan and all contributors!) but I ve run into a snag. Say I want to insert XML into the body ...

REST Windows Phone Photo upload

I m trying to upload a photo to a REST api in a Windows Phone 7 application using RestSharp for my Gets/Posts. The post parameters are as follows: photo: The photo, encoded as multipart/form-...

RestSharp v. WebClient?

I m building a Windows Phone 7 Silverlight app. Is there any reason to use RestSharp instead of WebClient? I ve looked around on the RestSharp site, but it s not immediately obvious what the benefits ...

Using restsharp in c# to consume last.fm services

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&...

热门标签