title: Count Number of Elements in JSON string with Json.NET in C#
body: <p>I have a JSON string that looks like this:</p>
  
  <pre><code>{
  "package1": {
      "type": "envelope",
      "quantity": 1,
      "length": 6,
      "width": 1,
      "height": 4
  },
  "package2": {
      "type": "box",
      "quantity": 2,
      "length": 9,
      "width": 9,
      "height": 9
  }
  }
  </code></pre>
  
  <p>I'm using the Json.NET LINQ to JSON functionality to handle my JSON string, but I'm wondering how I can find the total number of nodes/elements/keys (I'm not really sure what to call them) in my string. For example, the above string has package1 and package2 so I'm wondering how I can get it to return the integer 2. Sometimes I might only have one package, in which case, I'd like it to return the integer 1. Other times I might have 20 packages (in that case I'd like it to return 20).</p>
  
  <p>My JObject looks like this:</p>
  
  <pre><code>JObject o = JObject.Parse(myJsonString);
  </code></pre>
  
  <p>Any ideas? Thanks for any help.</p>