Click here to Skip to main content
15,937,003 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm a beginner, I have been trying JSON parsing POST and GET method from local API.

C#
using (HttpClient client = new HttpClient())
               {
                   pbWeather.Visibility = System.Windows.Visibility.Visible;
                   client.BaseAddress = new Uri("http://192.168.1.19/projects/t20lite/index.php/api/api/get_players?userid=1&deviceuniqueid=123&devicetime=456");
                   var url = "get_players?userid=1&deviceuniqueid=123&devicetime=456";

                   client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                   HttpResponseMessage response = await client.GetAsync(String.Format(url, txtCountryName.Text));

                   if (response.IsSuccessStatusCode)
                   {
                       var data = response.Content.ReadAsStringAsync();
                       var weatherdata = JsonConvert.DeserializeObject<PlayersInfo>(data.Result.ToString());

                       spWeatherInfo.DataContext = weatherdata;

                   }
                   pbWeather.Visibility = System.Windows.Visibility.Collapsed;
               }
           }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900