Created
September 13, 2016 03:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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