I have a web service (I can't edit) with this structure:
/users
{
"response" : {
"users": [{"name": "John"},{"name": "Jack"}]
},
"page" : { "current":1, "total":1}
}
/pets
{
"response" : {
"pets": [{"name": "Fido"},{"name": "Tweety"}]
},
"page" : { "current":1, "total":1}
}
As you can see the property name in the "response" property changes. How can deserialize a generic response with RestSharp? I don't want to write a Response class for every resource.
I have written the following generic Response class
class RestResponse{
public ResponseBody response { get; set; }
public ResponsePage page { get; set; }
}
class ResponseBody {
public List<dynamic> resourceList { get; set; }
}
class ResponsePage {
public int current { get; set; }
public int total { get; set; }
}
class User { public string name {get; set;} }
class Pet { public string name {get; set;} }
Of course RestSharp can't link the dynamic json property with the ResponseBody.list attribute. How can I do this?