Created
September 18, 2022 14:38
-
-
Save EgorBo/ac7dd8ccbf9fe993f766505d5ad550cb to your computer and use it in GitHub Desktop.
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.Text.Json; | |
using System.Text.Json.Serialization; | |
User? user = JsonSerializer.Deserialize<User>( | |
await new HttpClient().GetStringAsync("https://jsonplaceholder.typicode.com/todos/1"), MyJsonContext.Default.User); | |
Console.WriteLine($"id={user?.id}, title={user?.title}"); | |
public record User(int userId, int id, string title, bool completed); | |
[JsonSerializable(typeof(User))] | |
internal partial class MyJsonContext : JsonSerializerContext {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment