I'm using the Yahoo fantasy sports api. I'm getting a result like this:
"player": [
{
...
"eligible_positions": {
"position": "QB"
},
...
},
{
...
"eligible_positions": {
"position": [
"WR",
"W/R/T"
]
},
...
},
How is it that I can deserialize this?
My code looks like this:
var json = new JavaScriptSerializer();
if (response != null)
{
JSONResponse JSONResponseObject = json.Deserialize<JSONResponse>(response);
return JSONResponseObject;
}
And in my JSONResponse.cs file:
public class Player
{
public string player_key { get; set; }
public string player_id { get; set; }
public string display_position { get; set; }
public SelectedPosition selected_position { get; set; }
public Eligible_Positions eligible_positions { get; set; }
public Name name { get; set; }
}
public class Eligible_Positions
{
public string position { get; set; }
}
When I run this, since eligible_positions can return both a string and a string array, I keep getting the error "Type 'System.String' is not supported for deserialization of an array".
I've also tried turning public string position { get; set; }
to public string[] position { get; set; }
but I still get an error.
How should I handle this?