Code
·
64 lines
·
1221 bytes
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Text.Json;
namespace Object2Json.Test;
public class Tester
{
public static void Main()
{
var dict = new Dictionary<string, object>();
var t1 = new Test1()
{
Name = "alphons",
Age = 50,
Changed = DateTime.Now,
Gender = TypeEnum.Male,
Buf1 = [1, 2, 3, 4, 5]
};
t1.Buf2[3] = 0xff;
t1.Doubles2.Add([1.12, 2.34, 3.45]);
t1.Doubles2.Add([4.32, 3.21, 2.10]);
//var json1 = BetterSerializer.Serialize(t1);
//File.WriteAllText("test.json", json1);
//return;
var t2 = new Test1()
{
Name = "annet",
Age = 51,
Changed = DateTime.Now.AddDays(-1),
Gender = TypeEnum.Female
};
t2.Dict.Add("par 1", 777.888M);
t2.Dict.Add("par 2", 999.111M);
t1.Partner = t2;
dict.Add("man", t1);
dict.Add("vrouw", t2);
var json = ObjectJsonSerializer.Serialize(dict, new JsonSerializerOptions()
{
WriteIndented = true
});
File.WriteAllText("test.json", json);
var dictcopy = ObjectJsonSerializer.DeSerialize(json);
var jsoncopy = ObjectJsonSerializer.Serialize(dictcopy, new JsonSerializerOptions()
{
WriteIndented = true
});
//File.WriteAllText("test2.json", jsoncopy);
if (json == jsoncopy)
Console.WriteLine("same");
}
}