Get object from response

82 views
Skip to first unread message

Felix Czylwik

unread,
May 18, 2013, 6:03:13 PM5/18/13
to rest...@googlegroups.com
Hello,

I'm new to restsharp.

This example is in the latest version not working: https://github.com/restsharp/RestSharp/wiki/Recommended-Usage

That's because response.Data doesn't exist on IRestResponse.

How can I get my object from the response?

My response content is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <region:regions xmlns:region="http://rest.immobilienscout24.de/schema/search/region/1.0"> <region> <name>Porta Westfalica</name> <geoCodeId>1276010032008</geoCodeId> <amount>0</amount> </region> </region:regions>

My class is:

namespace ImmoScout24RestApiTest.Models
{
class RegionInfo
{
public string Name { get; set; }
public int GeoCodeId { get; set; }
public int Amount { get; set; }
}
}

And my code is:

var geoRequest = new RestRequest { Resource = "restapi/api/search/v1.0/region" };
geoRequest.AddParameter("q", "porta");

IRestResponse response = client.Execute<List<RegionInfo>>(geoRequest);

 
I hope you can help me.

Thank you

Pete Johanson

unread,
May 18, 2013, 6:06:36 PM5/18/13
to rest...@googlegroups.com

Felix,

Execute<T> actually returns an IRestResponse<T> instance. IRestResponse<T> is a subinterface of IRestResponse that adds the Data property.

-pete

--
You received this message because you are subscribed to the Google Groups "RestSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restsharp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Felix Czylwik

unread,
May 18, 2013, 7:13:05 PM5/18/13
to rest...@googlegroups.com
Oh, I see.

Thank you very much.

The cast is still failing, I think my model class is wrong for this xml response.
Can you tell me how the model should look to get it working?

Felix
Reply all
Reply to author
Forward
0 new messages