Click or drag to resize
Json.NET

Convert JSON to a Type

 

This sample converts LINQ to JSON objects to .NET types using ToObject(Type).

Sample
Usage
JValue v1 = new JValue(true);

bool b = (bool)v1.ToObject(typeof(bool));

Console.WriteLine(b);
// true

int i = (int)v1.ToObject(typeof(int));

Console.WriteLine(i);
// 1

string s = (string)v1.ToObject(typeof(string));

Console.WriteLine(s);
// "True"