Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 788 Bytes

ToObjectComplex.md

File metadata and controls

34 lines (27 loc) · 788 Bytes

Convert JSON to a Type

This sample converts LINQ to JSON objects to .NET types using Argon.JToken.ToObject<T>.

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

snippet source | anchor