Currently I am trying to deserialize a json string from a http response. I have verified the string returned is valid JSON. When the deserialize function completes I have an array with undefined objects.
public async Task<IEnumerable<MemberRoster>> GetAsync(string groupNumber)
{
var httpClient = _httpClientFactory.CreateClient();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Add("client_id", Configuration["Microservices:RequestHeaders:client_id"]);
httpClient.DefaultRequestHeaders.Add("client_secret", Configuration["Microservices:RequestHeaders:client_secret"]);
var queryParams = new Dictionary<string, string>()
{
["groupNumber"] = groupNumber
};
var memberUri = QueryHelpers.AddQueryString(Configuration["Microservices:Member"], queryParams);
var response = await httpClient.GetAsync(memberUri).Result.Content.ReadAsStringAsync();
var data = JsonSerializer.Deserialize<IEnumerable<MemberRoster>>(response);
return data;
}
public class MemberRoster
{
[JsonPropertyName("health_id")]
string HealthId { get; set; }
};
JSON in response
CodePudding user response:
I need to add the public accessor to my properties.