blob: 3e088a966e079e4d7864bbf0e389ddbd6ecf64ee (
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
31
32
33
34
35
36
37
38
39
|
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
class Program
{
public static void Main()
{
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>();
}
|