Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smchristensen/c76ecc788d80a4ee6de89b241f82d11d to your computer and use it in GitHub Desktop.
Save smchristensen/c76ecc788d80a4ee6de89b241f82d11d to your computer and use it in GitHub Desktop.
Simple concept method for deserializing a JSON response to a class. No error checking is done so don't use this as is but use as a base.
private List<T> GetRestRequestList<T>(string url)
{
List<T> results = new List<T>();
var httpClient = new HttpClient();
var response = httpClient.GetAsync(new Uri(url)).Result;
//will throw an exception if not successful
response.EnsureSuccessStatusCode();
string content = response.Content.ReadAsStringAsync().Result;
results = JsonConvert.DeserializeObject<List<T>>(content);
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment