我有一个包含此 JSON 数据的 URL:
[{"title":"Snow White & the Huntsman","year":2012,"released":1338534000,"url":"http://localhost/movie/snow-white-and-the-huntsman-2012","trailer":"http://youtube.com/watch?v=11Wn-_uyT48","runtime":127,"tagline":"","overview":"After the Evil Queen marries the King, she performs a violent coup in which the King is murdered and his daughter, Snow White, is taken captive. Almost a decade later, a grown Snow White is still in the clutches of the Queen. In order to obtain immortality, The Evil Queen needs the heart of Snow White. After Snow escapes the castle, the Queen sends the Huntsman to find her in the Dark Forest.","certification":"PG-13","imdb_id":"tt1735898","tmdb_id":"58595","poster":"http://trakt.us/images/posters_movies/180748.1.jpg","images":{"poster":"http://trakt.us/images/posters_movies/180748.1.jpg","fanart":"http://trakt.us/images/fanart_movies/180748.1.jpg"},"watchers":15,"ratings":{"percentage":68,"votes":105,"loved":71,"hated":34},"genres":["Adventure","Fantasy","Action","Drama"]}
我正在尝试解析它并将其显示在我的地铁应用程序中,但我无法让它为我的生活工作!我已经尝试了很多这样的事情:
string trendingURL = "http://Localhost/movies/trending.json/";
MovieDetails newMovie = new MovieDetails();
newMovie.title = "";
newMovie.cover = "";
//DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(MovieDetails));
//StreamReader sr = new Stream(trendingURL);
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(trendingURL);
var str = await response.Content.ReadAsStreamAsync();
var ser = new DataContractJsonSerializer(typeof(MovieDetails));
var collection = (MovieDetails)ser.ReadObject(str);
var results = collection.title;