user2016425
user2016425

Reputation: 25

Deserializing nested XML list in RestSharp

I have response in XML in the following format:

<response>
  <projects>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
    <project>...</project>
  </projects>
</response>

I have created a 'Project' class with attributes that match the names of the tags inside the <project> tag of the XML. Since the <projects> tag contains a list of <project>s, I was trying to execute the request on the RestSharp client as:

var projectList = client.Execute<List<Project> >(request);

However, projectList.Data shows null. This makes sense because the deserializer wasn't able to find a 'Projects' class. But in segue, my question is: how do I get a list of <project>s when it is nested in another tag <projects>?

Upvotes: 0

Views: 1223

Answers (1)

aiapatag
aiapatag

Reputation: 3430

In your Response class, have a property public List<Project> Projects { get; set; }.

This way, it will map the <projects> to your property Projects.

Upvotes: 1

Related Questions