Im trying to make a WPF application for movies, where i can look up a move, and get some info. But i cant get the JSON content into the page. I constanly get different errors, and i cant figger this one out anymore. Even AI's are give me all kinda solutions, but end up going in circle.
This is my MovieViewModel.cs:
private async void InitializeViewModel(){ var MovieURL = "https://xxxxx/page-1.json"; var movieCollectionList = new List<MovieInfo>(); using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(MovieURL); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var APIsearchResault = JsonConvert.DeserializeObject<dynamic>(content); try { if (APIsearchResault.Response!= null) { foreach (var movie in APIsearchResault.Search) { Console.WriteLine(movie.Title); movieCollectionList.Add( new MovieInfo { Title = movie.Title, TmdbId = movie.TmdbId, } ); } } } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); } } } Movies = movieCollectionList; _isInitialized = true;}
private async void InitializeViewModel(){ var MovieURL = "https://xxxxx/page-1.json"; var movieCollectionList = new List<MovieInfo>(); using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(MovieURL); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var APIsearchResault = JsonConvert.DeserializeObject<dynamic>(content); try { if (APIsearchResault.Response!= null) { foreach (var movie in APIsearchResault.Search) { Console.WriteLine(movie.Title); movieCollectionList.Add( new MovieInfo { Title = movie.Title, TmdbId = movie.TmdbId, } ); } } } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); } } } Movies = movieCollectionList; _isInitialized = true;}
This is the JSON content:
{ "result": [ { "imdb_id": "tt9281138", "tmdb_id": "972423", "title": "A Million Days 2023", }, .....
{ "result": [ { "imdb_id": "tt9281138", "tmdb_id": "972423", "title": "A Million Days 2023", }, .....
But i keep getting error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.NullReferenceException: 'Object reference not set to an instance of an object.'