Created
June 17, 2013 15:51
-
-
Save claudiosanchez/5797968 to your computer and use it in GitHub Desktop.
Need to get Json data from a web service; As Easy as 1-2-3 with Json.NET, C# 5.0 and async.
This file contains hidden or 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
| // | |
| // WebDataHelper.cs | |
| // | |
| // Author: | |
| // Claudio Sanchez <claudio@megsoftconsulting.com> | |
| // | |
| // Copyright (c) 2013 Megsoft Consulting Inc | |
| // | |
| // | |
| using System; | |
| using System.Net.Http; | |
| using System.Threading.Tasks; | |
| namespace myMDApp | |
| { | |
| public class WebDataHelper<T> where T:class | |
| { | |
| public async Task<T> GetData(string url) | |
| { | |
| var rawData = await new HttpClient ().GetStringAsync(url); | |
| T parsedObject = Newtonsoft.Json.JsonConvert.DeserializeObject<T> (rawData); | |
| return parsedObject; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment