Created
June 25, 2012 16:10
-
-
Save scottksmith95/2989512 to your computer and use it in GitHub Desktop.
JSON from API as a GitHubUser using Json.Net Enhanced
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
using System; | |
using System.Net; | |
public class ApiRequest | |
{ | |
readonly static WebClient WebClient = new WebClient(); | |
public static string GetJson(Uri uri) | |
{ | |
return WebClient.DownloadString(uri); | |
} | |
} |
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
public class GitHubUser | |
{ | |
[JsonProperty("created_at")] | |
public string Created { get; set; } | |
[JsonProperty("type")] | |
public string Type { get; set; } | |
[JsonProperty("blog")] | |
public object Blog { get; set; } | |
[JsonProperty("public_gists")] | |
public int PublicGists { get; set; } | |
[JsonProperty("gravatar_id")] | |
public string GravatarId { get; set; } | |
[JsonProperty("company")] | |
public object Company { get; set; } | |
[JsonProperty("email")] | |
public object Email { get; set; } | |
[JsonProperty("followers")] | |
public int Followers { get; set; } | |
[JsonProperty("following")] | |
public int Following { get; set; } | |
[JsonProperty("hireable")] | |
public bool Hireable { get; set; } | |
[JsonProperty("public_repos")] | |
public int PublicRepos { get; set; } | |
[JsonProperty("bio")] | |
public string Bio { get; set; } | |
[JsonProperty("html_url")] | |
public string HtmlUrl { get; set; } | |
[JsonProperty("name")] | |
public string Name { get; set; } | |
[JsonProperty("url")] | |
public string Url { get; set; } | |
[JsonProperty("location")] | |
public string Location { get; set; } | |
[JsonProperty("avatar_url")] | |
public string AvatarUrl { get; set; } | |
[JsonProperty("id")] | |
public int Id { get; set; } | |
[JsonProperty("login")] | |
public string Login { get; set; } | |
} |
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
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