Skip to content

Instantly share code, notes, and snippets.

@scottksmith95
Created June 25, 2012 15:56
Show Gist options
  • Save scottksmith95/2989408 to your computer and use it in GitHub Desktop.
Save scottksmith95/2989408 to your computer and use it in GitHub Desktop.
JSON from API as a GitHubUser using Json.Net
using System;
using System.Net;
public class ApiRequest
{
readonly static WebClient WebClient = new WebClient();
public static string GetJson(Uri uri)
{
return WebClient.DownloadString(uri);
}
}
public class GitHubUser
{
public string created_at { get; set; }
public string type { get; set; }
public object blog { get; set; }
public int public_gists { get; set; }
public string gravatar_id { get; set; }
public object company { get; set; }
public object email { get; set; }
public int followers { get; set; }
public int following { get; set; }
public bool hireable { get; set; }
public int public_repos { get; set; }
public string bio { get; set; }
public string html_url { get; set; }
public string name { get; set; }
public string url { get; set; }
public string location { get; set; }
public string avatar_url { get; set; }
public int id { get; set; }
public string login { get; set; }
}
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
class Program
{
const string GitHubPath = "https://api.github.com/users/scottksmith95";
static void Main(string[] args)
{
var gitHubUri = new Uri(GitHubPath);
var json = ApiRequest.GetJson(gitHubUri);
var jsonObject = JsonConvert.DeserializeObject<GitHubUser>(json);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment