title: Deserialize JSON returned from JsonDiffPatch.Diff() in c#
body: <p>I am comparing two json objects using JsonDiffPatch.Diff() method and I get the below JSON Structure:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    "complexity": {
      "_t": "a",
      "0": {
        "phases": {
          "_t": "a",
          "0": {
            "activities": {
              "_t": "a",
              "_0": [
                {
                  "name": "NAME",
                  "sortId": 15,
                  "isCritical": true,
                  "url": "https://google.com",
                  "processGroupName": "pgm",
                  "isDeliverable": "no"
                },
                0,
                0
              ]
            }
          }
        }
      },
      "3": {
        "phases": {
          "_t": "a",
          "0": {
            "sortId": [
              55,
              0,
              0
            ]
          },
          "1": {
            "activities": {
              "_t": "a",
              "_0": [
                {
                  "name": "SName",
                  "sortId": 12,
                  "isCritical": false,
                  "url": "https://google.com",
                  "processGroupName": "pgm",
                  "isDeliverable": "Yes"
                },
                0,
                0
              ]
            }
          }
        }
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The result that I want is an object containing List of Phases which contains List of Activities. As per the above JSON I want:
  0[Phases and Related Activities]
  3[Phases and Related Activities]</p>
  
  <p>I have written the below code:</p>
  
  <pre><code>List&lt;JToken&gt; tokens = diffJson.Children().Children().ToList();
          foreach (var token in tokens)
          {
  
              //Console.WriteLine(token.ToJson());
              var phases = token["0"].Children().Children();
              Console.WriteLine(phases.Count());
              var activities = phases["0"].Children().Children();
              Console.WriteLine();
          }
  </code></pre>
  
  <p>But this will only be for the first set which is for "complexity"["0"]. But how to get the data into an object which contains List.</p>
  
  <p>I have tried the below code also:</p>
  
  <pre><code>JavaScriptSerializer serializer = new JavaScriptSerializer();
          dynamic item = serializer.Deserialize&lt;object&gt;(output);
  </code></pre>
  
  <p>Could anybody help me out in understanding how to Deserialize this complex JSON into simple objects?</p>
  
  <p>I am thinking I will ignore "_t":"a" object under phases and start reading activities(again ignoring "_t": "a" object). Let me see how successful I will be.</p>
  
  <p>Expected Output will be creating objects of below classes:</p>
  
  <pre><code>using System;
  using System.Generic;
  public class Difference {
  public List&lt;Phase&gt; Phases { get; set; }
  }
  
  public class Phase {
      //For other properties like sortID
      public List&lt;Dictionary&lt;string, string&gt;&gt; Properties { get; set; }
      public List&lt;Activity&gt; Activites { get; set; }
  }
  
  public class Activity {
      public string name { get; set; }
      public int sortId { get; set; }
      public bool isCritical { get; set; }
      public string url { get; set; }
      public string processGroupName { get; set; }
      public string isDeliverable { get; set; }
  }
  </code></pre>
  
  <p>Below is the code which partially works:</p>
  
  <pre><code>JavaScriptSerializer serializer = new JavaScriptSerializer();
          dynamic item = serializer.Deserialize&lt;object&gt;(output);
          foreach (KeyValuePair&lt;string, dynamic&gt; complexity in item["complexity"])
          {
              if (complexity.Key != "_t")
              {
                  foreach (KeyValuePair&lt;string, dynamic&gt; phases in complexity.Value["phases"])
                  {
                      if (phases.Key != "_t")
                          foreach (KeyValuePair&lt;string, dynamic&gt; activities in phases.Value["activities"])
                      {
                          Console.WriteLine(activities.Value);
                      }
                  }
              }
          }
  </code></pre>
  
  <p>But this loop breaks when simple key value like sortId comes into picture.</p>
  
  <p>Thanks in Advance.</p>