Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created September 18, 2022 14:38
Show Gist options
  • Save EgorBo/ac7dd8ccbf9fe993f766505d5ad550cb to your computer and use it in GitHub Desktop.
Save EgorBo/ac7dd8ccbf9fe993f766505d5ad550cb to your computer and use it in GitHub Desktop.
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