title: Decoding JSON Data from PHP Page Using Jquery
body: <p>I want to take data from database and save it in an array.
  Like this</p>
  
  <pre><code> var locations = [ ['Current', 18.53515053, 73.87944794, 2],
  
    ['VimanNagar', 18.5670762, 73.9084194, 1]
  ];
  </code></pre>
  
  <p>First of all I have created a php page</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "citytrans";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT * FROM driver_location";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
         echo json_encode($row);
      }
  } else {
      echo "0 results";
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>which gives me below result</p>
  
  <pre><code>{"driver_id":"1","driver_lat":"18.53515053","driver_lng":"73.87944794","driver_code":"122"}{"driver_id":"2","driver_lat":"18.53640175","driver_lng":"73.88206482","driver_code":"133"}
  </code></pre>
  
  <p>Now I want to convert this into an array using Jquery (I want to decode it ), I just want <code>drivers_lat</code> and <code>drivers_lng</code> value from my jSON data fetched form the database show above.</p>
  
  <p>I am using below code to parse the data form json</p>
  
  <pre><code>jQuery.ajax({                              
      url: baseurl +  "getdriverlocation.php",
      type: "JSON",
      async: false,
      success: function(data){
             var myArray = JSON.parse(data);
                  console.log(myArray.driver_lat)
      } 
  });
  </code></pre>
  
  <p>but it is giving me error (shown below)</p>
  
  <blockquote>
    <p>SyntaxError: JSON.parse: unexpected non-whitespace character after
    JSON data at line 1 column 92 of the JSON data</p>
  </blockquote>
  
  <p>I just want the two values from json data and save it in an array variable</p>
  
  <p>Please help</p>