Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从JSON请求中获取数据并在metro应用程序中显示_C#_Json_Parsing_Microsoft Metro - Fatal编程技术网

C# 如何从JSON请求中获取数据并在metro应用程序中显示

C# 如何从JSON请求中获取数据并在metro应用程序中显示,c#,json,parsing,microsoft-metro,C#,Json,Parsing,Microsoft Metro,我有一个包含以下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":"

我有一个包含以下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"]}
我试图解析它并在我的metro应用程序中显示它,但我无法让它为我的生活工作!我尝试过很多事情,比如:

        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;
你去图书馆了吗?根据Codeplex,它也支持Windows 8,因此您可以执行以下操作:

var o = JObject.Parse(YOUR_JSON_STRING);
var newMovie = new MovieDetails();
newMovie.title = (string)o["title"];
newMovie.cover = (string)o["cover"];
使用

使用speakeasy:

var client = new HttpClient("http://Localhost/");
var details = client.Get("movies/trending.json").OnOk().As<MovieDetails>();
var-client=新的HttpClient(“http://Localhost/");
var details=client.Get(“movies/trending.json”).OnOk().As();

您可以使用nuget安装speakeasy。

-1
JObject.Parse
将引发异常,因为它是
JArray
我喜欢这种方法,但由于它们是动态的,我将如何检索这样的信息以供使用?这似乎不适用于.net 4.5,它会很快支持它吗?它不必支持.net 4.5,您可以将.net 4.0程序集与.net 4.5程序集一起使用。
var client = new HttpClient("http://Localhost/");
var details = client.Get("movies/trending.json").OnOk().As<MovieDetails>();