bperin42
asked on
How do I traverse this multidimensional JSON array/obj
I'm creating an AJAX script with PHP, and JS.
The PHP takes GET parameters, returns some data from the database. I need this data to be usable through javascript. My php verison < 5.2 so I dont have JSON encode. So far i've been able to get PHP to format a JSON array, the data looks like the following
{"6":{"lat":"34.409425","l ng":"-119. 861470"}," 5":{"lat": "34.409414 ","lng":"- 119.861221 "},"8":{"l at":"34.41 0934","lng ":"-119.86 1718"},"10 ":{"lat":" 34.410503" ,"lng":"-1 19.863998" },"9":{"la t":"34.412 089","lng" :"-119.866 134"},"3": {"lat":"34 .409475"," lng":"-119 .854704"}, "7":{"lat" :"34.41315 3","lng":" -119.85543 0"},"15":{ "lat":"34. 414979","l ng":"-119. 712181"}," 14":{"lat" :"34.41497 9","lng":" -119.71218 1"},"11":{ "lat":"34. 414979","l ng":"-119. 712181"}," 13":{"lat" :"34.41497 9","lng":" -119.71218 1"}}
The first key is a uuid then the following key is another array with latitude and logitude. I need to extract this information from javascript.
The PHP takes GET parameters, returns some data from the database. I need this data to be usable through javascript. My php verison < 5.2 so I dont have JSON encode. So far i've been able to get PHP to format a JSON array, the data looks like the following
{"6":{"lat":"34.409425","l
The first key is a uuid then the following key is another array with latitude and logitude. I need to extract this information from javascript.
function get_map()
{
var distance = $("#distance").val();
var sort = $("input[name='sort']:checked").val();
var who = $("input[name='who']:checked").val();
$.getJSON("ajax/ajax_get_locations_map.php",{distance: ""+distance+"",who: ""+who+"",sort: ""+sort+""}, function(data){
var obj = (data);
$.each(obj, function(i, val) {
//need help at this point to get variables
});
});
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.