using System.Text; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Unicode; namespace IS_Lab2_JSON_CS; public static class SerializeJson { public static void Run(DeserializeJson deserializeJson, string fileLocation) { var list = new List(); foreach (var obj in deserializeJson.Data.RootElement.EnumerateArray()) { list.Add(new { Kod_TERYT = obj.GetProperty("Kod_TERYT"), Województwo = obj.GetProperty("Województwo"), Powiat = obj.GetProperty("Powiat"), typ_JST = obj.GetProperty("typ_JST"), nazwa_urzędu_JST = obj.GetProperty("nazwa_urzędu_JST"), miejscowość = obj.GetProperty("miejscowość"), telefon_z_numerem_kierunkowym = $"{obj.GetProperty("telefonkierunkowy").ToString().Trim()}{obj.GetProperty("telefon").ToString().Trim()}" }); } File.WriteAllText(fileLocation, JsonSerializer.Serialize(list, new JsonSerializerOptions(JsonSerializerOptions.Default) { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }), Encoding.UTF8); } public static void Run(string origin, string fileLocation) { var deserialized = new DeserializeJson(origin); Run(deserialized, fileLocation); } }