Hello,
I have a problem getting data from the JSON file that I got by calling API.
I was able to call API and get the JSON file as text but when I wanted to split the JSON file into C # variables, I couldn't.
This is the json file: https://paste.myst.rs/loj5h85d
and this is my c# script: using System; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Newtonsoft.Json; using System.Collections.Generic; namespace ApiCalling { public class area { public int Id { get; set; } public string Name { get; set; } public string CountryCode { get; set; } public string EnsignUrl { get; set; } } public class currentSeason { public int Id { get; set; } public string StartDate { get; set; } public string EndDate { get; set; } public int CurrentMatchday { get; set; } public string Winner { get; set; } } public class competition { public int Id { get; set; } public area Area { get; set; } public string Name { get; set; } public string Code { get; set; } public string EnsignUrl { get; set; } public string Plan { get; set; } public currentSeason CurrentSeason { get; set; } public int NumberOfAvailableSeasons { get; set; } public string LastUpdated { get; set; } } public class theComptitions { public List<competition> Competitions { get; set; } = new List<competition>(); public int Count { get; set; } } class Program { static void Main(string[] args) { RunAsync().Wait(); } static async Task RunAsync() { using (var Apiclient = new HttpClient()) { // New code: Apiclient.BaseAddress = new Uri("http://api.football-data.org/"); Apiclient.DefaultRequestHeaders.Accept.Clear(); Apiclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Apiclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("X-Auth-token", "MyApiCode"); // GET HttpResponseMessage response = await Apiclient.GetAsync("v2/competitions"); if (response.IsSuccessStatusCode) { theComptitions combtitions = await response.Content.ReadAsAsync<theComptitions> (); Console.WriteLine(combtitions.Count); } } } } }
And I have another question: How can I get one of the combinations?
