Client application I don't have much control over has an established pattern for making calls to a particular API. Drilling down into the existing methods I find it's using System.Net.Http.Json
and calling response.Content.ReadFromJsonAsync<TResponse>(content)
, which I believe just takes a a target type TResponse
and tries to convert the passed JSON string accordingly.
I've gotten this to work great in every scenario except one - where the response from the API is an unlabeled array:
[{value: "stuff1"}, {value: "stuff2"}, {value: "stuff3"}]
Every other JSON response object looks something like this:
{
data: ["blah", "blah", "blah"]
value: 15,
prop: "whatever"
}
And example working Type:
[JsonPropertyName("data")]
public IList<string> Data {get;set}
[JsonPropertyName("value")]
public int Value {get;set}
[JsonPropertyName("prop")]
public string Prop {get;set}
But my problem response doesn't have any named keys, it's just an array... so how do I create a Type
for an array with no key?