0
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來轉換轉換JSON的數組字段列出
{
"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
}
我想設置movies
爲results
陣列。我的解決方案(我在這裏找到的)是關於將整個json(pagem results,total_results,total_pages)設置爲movies
。事實上,json的答案是一個單一的對象。
如何深入瞭解此json(轉換時)將List<Movie> movies
設置爲results
數組?