I am new in Xamarin Forms and I am trying to create a method that requests a list of items from an API. However, I am not able to compile the solution due to the error message
"Cannot Convert From String to NewtonSoft.Json.JsonReader" in the line
var Items = JsonSerializer.Deserialize<Dictionary<string, Paises>>(content);
Here is the entire routine:
public static async Task<List<Paises>> GetPaisesActivosAsync()
{
string baseUri = new BaseUri().baseUri;
string sufixUri = "/PaisesApi/GetActives";
var uri = baseUri + sufixUri;
List<Paises> listaPaisesActivos = null;
HttpResponseMessage response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
var Items = JsonSerializer.Deserialize<Dictionary<string, Paises>>(content);
}
return listaPaisesActivos;
}
Thanks in advance for your support.
Regards,
JsonConvert.DeserializeObject
. Plus, recommended usingvar
instead ofstring
. – Hyracoid