Created
October 20, 2017 08:30
-
-
Save tuyen-vuduc/50d5c3cb897d7e0f7e8f7e7f7adae072 to your computer and use it in GitHub Desktop.
Parse JSON from HttpContent with JSON.NET
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
static class HttpContentExtensions | |
{ | |
public static async Task<T> DeserializeJsonObjectAsync<T>(this HttpContent content) | |
{ | |
using (var stream = await content.ReadAsStreamAsync()) | |
{ | |
using (var textReader = new StreamReader(stream)) | |
{ | |
using (var jsonReader = new JsonTextReader(textReader)) | |
{ | |
var serializer = new JsonSerializer | |
{ | |
//ContractResolver = new DefaultContractResolver | |
//{ | |
// NamingStrategy = new SnakeCaseNamingStrategy() | |
//} | |
}; | |
return serializer.Deserialize<T>(jsonReader); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment