Files
Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Documentation/Examples/Linq/ToObjectComplex.cs
T
James Newton-King 68eacc480b -JSON Schema fixes
-Fixed static values being included with fields serialization
-Examples! (work in progress)
2013-01-23 21:39:54 +13:00

42 lines
775 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class ToObjectComplex
{
public class Person
{
public string Name { get; set; }
}
public void Example()
{
string json = @"{
""d"": [
{
""Name"": ""John Smith""
},
{
""Name"": ""Mike Smith""
}
]
}";
JObject o = JObject.Parse(json);
JArray a = (JArray)o["d"];
IList<Person> person = a.ToObject<IList<Person>>();
Console.WriteLine(person[0].Name);
// John Smith
Console.WriteLine(person[1].Name);
// Mike Smith
}
}
}