title: Get Json arrays values in a javascript function
body: <p>I have defined a json array in a file as </p>
  
  <pre><code>{
      mainServiceBar= [
          { "mainServiceName":"ECONOMIC SERVICES" , "mainServiceValue":"23.2" },
          { "mainServiceName":"SOCIAL SERVICES" , "mainServiceValue":"34.5" },
          { "mainServiceName":"DEFENSE" , "mainServiceValue":"4.5" },
          { "mainServiceName":"GENERAL PUBLIC SERVICES" , "mainServiceValue":"19" },
          { "mainServiceName":"DEBT BURDEN" , "mainServiceValue":"18.8" },
      ];
  
  
      subServiceBar1: [
          { "subServiceName":"agriculture" , "subServiceValue":"12.5" },
          { "subServiceName":"trade" , "subServiceValue":"12.5" },
          { "subServiceName":"tourism" , "subServiceValue":"12.5" },
          { "subServiceName":"power and energy" , "subServiceValue":"12.5" },
          { "subServiceName":"water resource" , "subServiceValue":"12.5" }
          { "subServiceName":"communication roads" , "subServiceValue":"12.5" }
          { "subServiceName":"other economic services" , "subServiceValue":"12.5" },
          { "subServiceName":"subsidy" , "subServiceValue":"12.5" },
      ];
  }
  </code></pre>
  
  <p>now i want these json arrays values in a javascript function , I have done few things but it I didn't get the values , my code is as follows :</p>
  
  <pre><code>function getJsonArray() {
      return $.getJSON("myjson.js"); 
  }
  
  function socialservice(thisv) {
      json = getJsonArray();
  
      for (var key in json) {
          if (json.hasOwnProperty(key)) {
              var item = json[key];
  
              alert(item.mainServiceName);
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>*<strong>*EDITED</strong>
  I have also tried this  :</p>
  
  <pre><code>$.getJSON("myjson.json", function(data) {
      alert("val");
  
      var items = [];
  
      $.each(data, function(key, val) {
          alert(val);
      });
  });
  </code></pre>
  
  <p>but it do\esn't alert anything means it do not get json data</p>
  
  <p>It alerts undefined , Please suggest me some way to get the values , Thanks</p>