I have the following JSON to POST to my Web API endpoint.
[
{
"name": "REGION",
"value": ["MA", "SE", "SW"]
}
]
The Web API endpoint is as follows
public class Parameter
{
public string Name { get; set; }
// Value can be string, string[], int, or int[]
public dynamic Value { get; set; }
}
[Route("{chart}/data/")]
[HttpPost]
public IHttpActionResult GetData(string chart, IList<Parameter> parameters)
{
// ... do stuff ...
}
Whenever value
in the JSON is an array the deserialized parameter's Value
is a JArray
rather than an array of string
, int
, etc. However, if value
is a simply a string
or number
then Value
in the deserialized parameters is also a string
or a number
.
What gives? Why isn't the array in the JSON being deserialized into an array of the proper type?