Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (38 loc) · 1.56 KB

File metadata and controls

47 lines (38 loc) · 1.56 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
public class StackExchangeUser
{
[JsonPropertyName("account_id")]
public int AccountId { get; set; }
[JsonPropertyName("display_name")]
public string DisplayName { get; set; }
[JsonPropertyName("profile_image")]
public string ProfileImage { get; set; }
[JsonPropertyName("reputation")]
public int Reputation { get; set; }
}
public class StackExchangeResponse<T>
{
public List<T> Items { get; set; }
public bool HasMore { get; set; }
public int QuotaMax { get; set; }
public int QuotaRemaining { get; set; }
}
public class Program
{
static async Task Main(string[] args)
{
var httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All };
// Set up the HttpClient and API endpoint URL
var client = new HttpClient(httpClientHandler);
var apiUrl = "https://api.stackexchange.com/2.3/users?order=desc&sort=reputation&site=stackoverflow";
// Call the API and deserialize the response into C# objects
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var response = await client.GetStringAsync(apiUrl);
var usersResponse = JsonSerializer.Deserialize<StackExchangeResponse<StackExchangeUser>>(response, options);
// Output the first user's display name and reputation
var firstUser = usersResponse?.Items[0];
Console.WriteLine($"User: {firstUser?.DisplayName}, Reputation: {firstUser?.Reputation}");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.