aboutsummaryrefslogtreecommitdiff
path: root/test/dotnet/projects/net6.0/Program.cs
blob: 6d7311261585a4cc6931ce8b8368fa3306649ad9 (plain) (blame)
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
using Newtonsoft.Json;

string json = @"{
  ""Name"": ""Inception"",
  ""ReleaseDate"": ""2010-07-08T00:00:00"",
  ""Genres"": [
    ""Action"",
    ""Thriller""
  ]
}";

Movie? m = JsonConvert.DeserializeObject<Movie>(json);

if (m == default)
{
    Console.WriteLine("Decoding failed!");
}
else
{
    Console.WriteLine($"Movie name: {m.Name}");
    Console.WriteLine($"Release Date: {m.ReleaseDate}");
    Console.WriteLine($"Genres: {string.Join(", ", m.Genres)}");
}

class Movie
{
    public string Name { get; set; } = "Default Name";
    public DateTime ReleaseDate { get; set; }
    public List<string> Genres { get; set; } = new List<string>();
}