I have a json file like: { total: 86, success: true, "rows": [ {"a1_id":"3231VB8", etc. etc.
My problem is that when using jquery for entering markers in google maps from eg this json file, it won’t do so until I replace <total: 86, success: true, "rows":> by <"markers":> at the start of the json file.
Ok no problem doing that, but when I do so another json requests from the same url/file is broken.
Question: how should I deal with this? Is there a way to change the gmap code to deal with my json file or sh:
function(data) {
$.each( data.markers, function(i, m) {
$('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(m.latitude, m.longitude), 'bounds':true } );
So essentially you’re asking how to rename the “rows” property from the JSON to be “markers”, because “markers” is what is used by that particular pieces of JS/jQuery code? And you need the change to be in that code so that the existing JSON can be used as is by other processes?
If so, why not just make the following small change in your JS/jQuery code to reference the “rows” property instead of “markers”:
The only change is to the first parameter passed to
$.each(). The “total” and “success” parameters from your JSON don’t actually need to be removed because they are simply ignored by the code you’ve shown (both before and after my change).If for some reason you need to actually modify the
dataobject, which I assume was created by parsing the JSON, you can try something like this:That is, create a new object that has a single property, “markers”, which references the “rows” array from the original object, and then re-assign the
datavariable to point to the new object. Then simply use your$.each()as is.