Skip to content

Instantly share code, notes, and snippets.

@ferventcoder
Created July 12, 2012 22:47
Show Gist options
  • Save ferventcoder/3101576 to your computer and use it in GitHub Desktop.
Save ferventcoder/3101576 to your computer and use it in GitHub Desktop.
RestSharp Issue - Response With Different Named Types - How do you set this up?
"votePerOption":[{"Option1Votes":0},{"Option2Votes":1},{"Option3Votes":2},{"Option4Votes":1}]
"votePerOption":[{"Option1Votes":0,"Option2Votes":null,"Option3Votes":null,"Option4Votes":null},{"Option1Votes":0,"Option2Votes":1,"Option3Votes":null,"Option4Votes":null},{"Option1Votes":0,"Option2Votes":null,"Option3Votes":2,"Option4Votes":null},{"Option1Votes":0,"Option2Votes":null,"Option3Votes":null,"Option4Votes":1}]
public class VoteResults
{
public List<VotePerOption> votePerOption { get; set; }
}
public class VotePerOption
{
public int Option1Votes { get; set; }
public int? Option2Votes { get; set; }
public int? Option3Votes { get; set; }
public int? Option4Votes { get; set; }
}
client.AddHandler("application/vnd.javascript", new JsonDeserializer());
@ferventcoder
Copy link
Author

Tried this instead:

public class MicropollVoteResults
{
    private Dictionary<string,int> _votePerOption = new Dictionary<string, int>(); 

    public Dictionary<string, int> votePerOption
    {
        get { return _votePerOption; }
        set { _votePerOption = value; }
    }

}

@ferventcoder
Copy link
Author

The fix is to do some post processing after the results come back...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment