public List<Movie> getPopularMovies()
{
List<Movie> movies = null;
var client = new HttpClient();
var task = client.GetAsync(url)
.ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonString = response.Content.ReadAsStringAsync();
jsonString.Wait();
movies = JsonConvert.DeserializeObject<List<Movie>>(jsonString.Result);
});
task.Wait();
return movies;
}
Json to convert
{
"page": 1,
"results": [
{
"poster_path": "/xfWac8MTYDxujaxgPVcRD9yZaul.jpg",
"adult": false,
"overview": "After his career is destroyed, a brilliant but arrogant surgeon gets a new lease on life when a sorcerer takes him under his wing and trains him to defend the world against evil.",
"release_date": "2016-10-25",
"genre_ids": [
28,
12,
14,
878
],
"id": 284052,
"original_title": "Doctor Strange",
"original_language": "en",
"title": "Doctor Strange",
"backdrop_path": "/hETu6AxKsWAS42tw8eXgLUgn4Lo.jpg",
"popularity": 55.113822,
"vote_count": 598,
"video": false,
"vote_average": 6.99
}
],
"total_results": 19676,
"total_pages": 984
}
I'd like to set movies as results array. My solution (what I found here) is about setting movies as the whole json (pagem results, total_results, total_pages). In fact the json answer is a single object.
How to get deeply inside this json (while converting) to set the List<Movie> movies to results array?