コード例 #1
0
        public ActionResult <Movie[]> GetMovie(String title)
        {
            //  this is my key. Register with IMDB and get your own
            String baseURL = "https://imdb-api.com/en/API/SearchMovie/k_lLeNEBFqX/";
            //  we are using the static MoviesController method GetJsonText to
            //  hit the IMDB movie API to get our list of movies (DRY)
            string movieResults = GetJsonText(baseURL + title);

            MovieHeader header = JsonSerializer.Deserialize <MovieHeader>(movieResults);

            return(header.results);
        }
コード例 #2
0
        public IActionResult Search(string title)
        {
            String baseURL      = "https://imdb-api.com/en/API/SearchMovie/k_lLeNEBFq/";
            string movieResults = MovieAPI.GetJsonText(baseURL + title);

            // Put a break point here and look at the movieResults
            //  it is a long string of text that looks like JSON
            //  Deserializer will look at the text and the MovieHeader
            //  object and recognize that MovieHeader is the object version
            //  of this JSON text
            //  WOW! this line of code does very cool stuff!!!
            MovieHeader header = JsonSerializer.Deserialize <MovieHeader>(movieResults);

            //  we are reusing the Index page. The AddOnly variable says only show the Add link
            ViewBag.AddOnly = true;
            return(View("Index", header.results));
        }