-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDeserializeDataSet.cs
51 lines (40 loc) · 1.13 KB
/
DeserializeDataSet.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
// Copyright (c) 2007 James Newton-King. All rights reserved.
// Use of this source code is governed by The MIT License,
// as found in the license.md file.
using System.Data;
public class DeserializeDataSet : TestFixtureBase
{
[Fact]
public void Example()
{
#region DeserializeDataSet
var json = """
{
'Table1': [
{
'id': 0,
'item': 'item 0'
},
{
'id': 1,
'item': 'item 1'
}
]
}
""";
var settings = new JsonSerializerSettings();
settings.AddDataSetConverters();
var dataSet = JsonConvert.DeserializeObject<DataSet>(json, settings);
var dataTable = dataSet.Tables["Table1"];
Console.WriteLine(dataTable.Rows.Count);
// 2
foreach (DataRow row in dataTable.Rows)
{
Console.WriteLine($"{row["id"]} - {row["item"]}");
}
// 0 - item 0
// 1 - item 1
#endregion
Assert.Equal(2, dataTable.Rows.Count);
}
}