Get c# object list from response.Content.ReadAsStringAsync()
You need to await the task like so:
var result = await response.Content.ReadAsStringAsync();
Danger of using var
, as now it inferred the type as Task<string>
. If you had tried:
string result = response.Content.ReadAsStringAsync();
It would have immediately given you an error that it can't cast Task<string>
to string
.
EDIT: The other error you have is that you are trying to deserialize the JSON into an object when it is actually an array.
List<BusinessUnit> businessunits = JsonConvert.DeserializeObject<List<BusinessUnit>>(result);
You could try this:
IEnumerable<BusinessUnit> result = await response.Content.ReadAsAsync<IEnumerable<BusinessUnit>>();
Saludos.