-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathToObjectComplex.cs
More file actions
51 lines (39 loc) · 1.02 KB
/
ToObjectComplex.cs
File metadata and controls
51 lines (39 loc) · 1.02 KB
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.
public class ToObjectComplex : TestFixtureBase
{
#region Types
public class Person
{
public string Name { get; set; }
}
#endregion
[Fact]
public void Example()
{
#region ToObjectComplex
var json = """
{
'd': [
{
'Name': 'John Smith'
},
{
'Name': 'Mike Smith'
}
]
}
""";
var o = JObject.Parse(json);
var a = (JArray) o["d"];
var person = a.ToObject<IList<Person>>();
Console.WriteLine(person[0].Name);
// John Smith
Console.WriteLine(person[1].Name);
// Mike Smith
#endregion
Assert.Equal("John Smith", person[0].Name);
Assert.Equal("Mike Smith", person[1].Name);
}
}