Click or drag to resize
Json.NETMaxDepth setting
 

This sample uses the MaxDepth setting to constrain JSON to a maximum depth when deserializing.

Sample
Usage
 1string json = @"[
 2  [
 3    [
 4      '1',
 5      'Two',
 6      'III'
 7    ]
 8  ]
 9]";
10
11try
12{
13    JsonConvert.DeserializeObject<List<IList<IList<string>>>>(json, new JsonSerializerSettings
14    {
15        MaxDepth = 2
16    });
17}
18catch (JsonReaderException ex)
19{
20    Console.WriteLine(ex.Message);
21    // The reader's MaxDepth of 2 has been exceeded. Path '[0][0]', line 3, position 12.
22}