Skip to content

Instantly share code, notes, and snippets.

@claudiosanchez
Created June 17, 2013 15:51
Show Gist options
  • Select an option

  • Save claudiosanchez/5797968 to your computer and use it in GitHub Desktop.

Select an option

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.
//
// 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