Skip to content

Instantly share code, notes, and snippets.

@scottksmith95
Created June 25, 2012 15:47
Show Gist options
  • Save scottksmith95/2989374 to your computer and use it in GitHub Desktop.
Save scottksmith95/2989374 to your computer and use it in GitHub Desktop.
JSON from API as an object using JavaScriptSerializer
using System;
using System.Net;
public class ApiRequest
{
readonly static WebClient WebClient = new WebClient();
public static string GetJson(Uri uri)
{
return WebClient.DownloadString(uri);
}
}
//Make sure to add a reference to the assembly System.Web.Extensions
using System;
using System.Web.Script.Serialization;
class Program
{
const string GitHubPath = "https://api.github.com/users/scottksmith95";
static readonly JavaScriptSerializer Serializer = new JavaScriptSerializer();
static void Main(string[] args)
{
var gitHubUri = new Uri(GitHubPath);
var json = ApiRequest.GetJson(gitHubUri);
var jsonObject = Serializer.Deserialize<object>(json);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment