static void Space() { string content = string.Empty; string spacePeopleUrl = "http://api.open-notify.org/astros.json"; using (var wc = new WebClient()) { content = wc.DownloadString(spacePeopleUrl); } SpacePersonModel spacePeopleFact = JsonSerializer.Deserialize<SpacePersonModel>(content); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("There are " + spacePeopleFact.People.Count + " in space right now!"); foreach (SpacePerson spacePerson in spacePeopleFact.People) { Console.WriteLine(spacePerson.Name + " is in " + spacePerson.Craft); } Console.WriteLine(); }
static void Space() { string content = string.Empty; string sapcePeopleUrl = "http://api.open-notify.org/astros.json"; WebRequest sapcePeopleReq = WebRequest.Create(sapcePeopleUrl); using (WebResponse wr = sapcePeopleReq.GetResponse()) using (Stream receiveStream = wr.GetResponseStream()) using (StreamReader sReader = new StreamReader(receiveStream, Encoding.UTF8)) content = sReader.ReadToEnd(); SpacePersonModel sapcePeopleFact = JsonSerializer.Deserialize <SpacePersonModel>(content); Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("There are " + sapcePeopleFact.people.Count() + " in space right now!"); foreach (SpacePerson spacePerson in sapcePeopleFact.people) { Console.WriteLine(spacePerson.name + " is in " + spacePerson.craft); } Console.WriteLine(""); }