static async Task Bereinfo(string nr) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(LinkPrincipal); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Console.WriteLine("-----Informatii bere-----\n"); HttpResponseMessage response = await client.GetAsync("beers/" + nr);; Bere bere = await response.Content.ReadAsAsync <Bere>(); //use JavaScriptSerializer from System.Web.Script.Serialization //string data = await response.Content.ReadAsStringAsync(); string data2 = await response.Content.ReadAsStringAsync(); data2 = Clear_info(data2); Console.WriteLine(data2); //use JavaScriptSerializer from System.Web.Script.Serialization JavaScriptSerializer JSserializer = new JavaScriptSerializer(); //deserialize to your class ListaBere = JSserializer.Deserialize <List <Bere> >(data2); //Console.WriteLine(ListaBerarie); for (int i = 0; i < ListaBere.Count; i++) { Console.WriteLine("Id bere:" + ListaBere[i].Id); Console.WriteLine("Tip bere:" + ListaBere[i].Name); Console.WriteLine("\n"); } } }
static async Task RunBere() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(LinkPrincipal); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Console.WriteLine("-----Meniu bere-----\n"); HttpResponseMessage response = await client.GetAsync("beers"); Bere bere = await response.Content.ReadAsAsync <Bere>(); //use JavaScriptSerializer from System.Web.Script.Serialization //string data = await response.Content.ReadAsStringAsync(); string data2 = await response.Content.ReadAsStringAsync(); string[] dataSplit = data2.Split(new string[] { "\"ResourceList\":" }, StringSplitOptions.RemoveEmptyEntries); data2 = Clear_beer(dataSplit[1]); //Console.WriteLine(data2); //use JavaScriptSerializer from System.Web.Script.Serialization JavaScriptSerializer JSserializer = new JavaScriptSerializer(); //deserialize to your class ListaBere = JSserializer.Deserialize <List <Bere> >(data2); //Console.WriteLine(ListaBerarie); for (int i = 0; i < ListaBere.Count; i++) { Console.WriteLine("Id bere:" + ListaBere[i].Id); Console.WriteLine("Tip bere:" + ListaBere[i].Name); Console.WriteLine("\n"); } } }