1

I am fetching data from API and trying to convert it into deserialized form. But gettting this error.

public static async Task<List<Movie>> GetAllMovies(int pageNumber, int pageSize)
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = httpClient.GetStringAsync(AppSettings.ApiUrl + String.Format("api/movies/AllMovies?sort=asc&pageNumber={0}&pageSize={1}",pageNumber,pageSize));
            return JsonConvert.DeserializeObject<List<Movie>>(response);

        }

2 Answers 2

6

Use await before response

  return JsonConvert.DeserializeObject<List<Movie>>(await response)
Sign up to request clarification or add additional context in comments.

Comments

1

Change your method to :

public static async Task<List<Movie>> GetAllMovies(int pageNumber, int pageSize)
{
    var httpClient = new HttpClient();
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
    var result = httpClient.GetStringAsync(AppSettings.ApiUrl + String.Format("api/movies/AllMovies?sort=asc&pageNumber={0}&pageSize={1}",pageNumber,pageSize));
    var response = await result.Content.ReadAsStringAsync();
    return JsonConvert.DeserializeObject<List<Movie>>(response);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.