Tuesday, July 26, 2016

simple json call from c#

string URL = "http://www.blah.com/";
                    string urlParameters = “?v=1”;
                   

                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(URL);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response = client.GetAsync(urlParameters).Result; 
                    if (response.IsSuccessStatusCode)
                    {
                        string dataObjects = response.Content.ReadAsStringAsync().Result;
                        var jss = new JavaScriptSerializer();
                        var dict = jss.Deserialize<Dictionary<string, dynamic>>(dataObjects);

                        foreach (Dictionary<string, object> x in dict["items"])

                        {

No comments:

Post a Comment