-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
77 lines (61 loc) · 1.99 KB
/
Program.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace test
{
class Program
{
static void Main(string[] args)
{
cell[] board2 = new cell[256];
for (int i = 0; i < board2.Length; ++i)
{
board2[i] = new cell();
board2[i].life = 0;
board2[i].color = "#FF0000";
}
/*
foreach (cell i in board2)
{
Console.WriteLine(i.life);
Console.WriteLine(i.color);
}
*/
board2[245].life = 1;
string jsonString;
jsonString = JsonSerializer.Serialize(board2);
Console.WriteLine(jsonString);
cell[] board = new cell[256];
for (int i = 0; i < board2.Length; ++i)
{
board[i] = new cell();
}
int count = 0;
using (JsonDocument document = JsonDocument.Parse(jsonString))
{
JsonElement root = document.RootElement;
//JsonElement studentsElement = root.GetProperty("Students");
foreach (JsonElement cell in root.EnumerateArray())
{
cell.TryGetProperty("life", out JsonElement lifeElement);
board[count].life = lifeElement.GetInt32();
//Console.WriteLine(lifeElement.ToString());
cell.TryGetProperty("color", out JsonElement colorElement);
board[count].color = colorElement.ToString();
//Console.WriteLine(colorElement.ToString());
count++;
}
}
foreach (cell i in board)
{
Console.WriteLine(i.life);
Console.WriteLine(i.color);
}
}
}
class cell
{
public int life { get; set; }
public string color { get; set; }
}
}