Trouble getting nested JSON objects with JavaScript

I’m trying to get the Store Latitude and Longitude values from the JSON below using JavaScript. JSONLint says I have valid JSON, and I’m able to get and use other parts of this JSON file (the “Charts” section, but not the “Maps” section). Not sure what I’m doing wrong here. Any ideas?

Here’s my JSON file:


{
     "Charts": {
          "Locations": [
	       {
	            "Views": 5,
		    "Clicks": 0,
		    "PhoneCalls": 0
	        },
		{
		    "Views": 7,
		    "Clicks": 1,
	            "PhoneCalls": 0
		}
           ]
     },
     "Maps": {
          "Locations": [
               {
                    "ID0": {
                         "Store": {
			      "Latitude": [COLOR="#008000"]59.327383[/COLOR],
			      "Longitude": [COLOR="#008000"]18.06747[/COLOR]
			 },
			 "Views": [
			     {
			          "Latitude": 59.32522,
				  "Longitude": 18.07002
			      },
			      {
				  "Latitude": 47.6097,
				  "Longitude": 122.3331
			      }
                         ]
                    },
                    "ID1": {
                         ...
                    }
               }
          ]
     }
}

Obviously, I removed a lot of data so you could see the data I need clearly, but it is organized in this way.

Here’s my JS:


$jq.getJSON("/path/to/file.json", function(json){
     var jsonData = eval(json);
     var locationStoreLocation = new google.maps.LatLng(jsonData.Maps.Locations.ID0.Store.Latitude, jsonData.Maps.Locations.ID0.Store.Longitude);
}

The “new google.maps.LatLng()” is required for the Google JavaScript API I’m using. The error I get in my browser’s javascript console is “Cannot read property ‘Store’ of undefined.”

Hi,

Maps.Locations contains an array so you’ll need to access it with an index.


id0 = jsonData.Maps.Locations[0].ID0;

Oh, of course! Thank you, markbrown4. It’s working now. :slight_smile: