I am new to JavaScript. My JavaScript (script.js) reads from a JSON file as shown below. The script reads without using JQuery. I followed THIS site for reference.
function readJSON() {
var LatLongData = JSON.parse(data);
var LatLng1 = new google.maps.LatLng(LatLongData[0]);
}
The JSON file (data.json), stored in the same location as the JavaScript is as below:
{ "data":
[
{"latitude" : "40.10246648", "longitude" : "-83.14877599"}
]
}
The html file is as shown below:
<script type="text/javascript" src="data.json"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MyKey&sensor=true"></script>
<body onload="readJSON()">
<div id="map-canvas"/>
</body>
I get 2 errors (both in chrome as well as Firebug) on the JSON file format. However, I verified online (http://jsonlint.com/) that the JSON file is of the right format. The errors I get are:
SyntaxError: missing ; before statement { "data":
ReferenceError: data is not defined ---> var LatLongData = JSON.parse(data);
What am I doing wrong here?