Created
January 27, 2022 20:33
-
-
Save tomekziel/67542ae11b9469e1688e833ff66f00a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.IO; | |
using System.Net.Http; | |
using System.Net.Http.Json; | |
using System.Text.Encodings.Web; | |
using System.Text.Json; | |
using System.Text.Json.Serialization; | |
using System.Text.Unicode; | |
const string apiPrefix = "https://portal.wroclaw.sa.gov.pl/api/slps/"; | |
var client = new HttpClient() | |
{ | |
BaseAddress = new Uri(apiPrefix) | |
}; | |
var courts = await client.GetFromJsonAsync<List<Court>>("courts"); | |
foreach (var court in courts) | |
{ | |
Console.WriteLine(court.Name); | |
var departments = await client.GetFromJsonAsync<List<Department>>($"courts/{court.Id}/departments"); | |
court.Departments = departments; | |
foreach (var department in departments) | |
{ | |
Console.WriteLine(" "+department.Name); | |
var repertories = await client.GetFromJsonAsync<List<String>>($"courts/{court.Id}/departments/{department.Id}/repertories"); | |
department.Repertories = repertories; | |
Console.WriteLine(" " + String.Join(", ", repertories)); | |
} | |
} | |
File.WriteAllText("out.txt", JsonSerializer.Serialize(courts, options: new JsonSerializerOptions() | |
{WriteIndented = true,Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.LatinExtendedA)})); | |
public class Court | |
{ | |
[JsonPropertyName("name")] | |
public string Name { set; get; } | |
[JsonPropertyName("zrskId")] | |
public int Id { set; get; } | |
[JsonPropertyName("departments")] | |
public List<Department> Departments { set; get; } | |
} | |
public class Department | |
{ | |
[JsonPropertyName("name")] | |
public string Name { set; get; } | |
[JsonPropertyName("zrskId")] | |
public int Id { set; get; } | |
[JsonPropertyName("number")] | |
public string Number { set; get; } | |
[JsonPropertyName("repertories")] | |
public List<string> Repertories { set; get; } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment