title: Having trouble with JSON and Javascript
body: <p>I am trying to make a simple sample previewer for my client project.
  The list of samples are stored in a JSON file. but the trouble is that I am not too familiar with using JSON, or programming itself, to be honest.
  I have written a short test code to see if this JSON file works well, but although I can access <code>sampleData</code> variable from firebug console, the <code>document.write(sampleData.length);</code> line seems to be unable to access <code>sampleData</code> for some reason. The error shows:  </p>
  
  <blockquote>
    <p>TypeError: sampleData is undefined</p>
  </blockquote>
  
  <p>I suspect it has to do with variable scopes, but I am not sure.</p>
  
  <pre><code>&lt;script type="text/javascript" src="js/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      var sampleData;
      $.getJSON('res/Samples.json',function(data){
          sampleData=data;
      });
      document.write(sampleData.length);
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>What should I do to make the <code>sampleData</code> variable to work with the rest of the code?</strong><br>
  I'm sorry I cannot disclose the contents of the json file. It contains an array of objects containing information of the products. it looks like</p>
  
  <pre><code>[
      {
      "aaa" : 000000;
      },
      {
      "bbb" : 111111;
      },
      {
      "ccc" : 222222;
      }
  ]
  </code></pre>
  
  <p>It's a quite generic form of JSON file, as far as I can tell.</p>