title: How to check if json array is empty in c#?
body: <p>I'm calling Google Maps and use System.JSON to parse the object. I grab my object using:</p>
  
  <pre><code>double placeLat = json["results"][0]["geometry"]["location"]["lat"];
  </code></pre>
  
  <p>Then I want to check wheater the third objects exists and if yes perform some actions, but apparently the following fails. I know that Google Maps returns 2 objects in this case and I want to check for the third one to avoid performing actions on null and passing them further.. The following works fine when Google Maps returns 3 objects so I believe my condition is wrong.</p>
  
  <pre><code>if (json["results"][2] != null) {
  
          }
  </code></pre>
  
  <p>I get this error: </p>
  
  <blockquote>
    <p>Index was out of range. Must be non-negative and less than the size of
    the collection. Parameter name: index</p>
  </blockquote>
  
  <p>Any ideas of how to properly build the if statement in case using System.JSON?</p>