I know there have been a lot of questions about how to handle JSON and I have tried quite a few, but am really stuck.
What I am trying to achieve is the following:
I load a JSON and in that JSON, there is information about photos. Each photos has several attributes, one of them being the latitude and longitude.These have not been specified for all the photo's. I want to have a JSON object in the end which contains only the photo's with a lat/long value.
The JSON looks like this:
{
"current_page": 1,
"total_pages": 2,
"total_items": 27,
"photos": [{
"id": 63151715,
"user_id": 430997,
"name": "Footsteps",
"description": "Traces in the dunes",
"camera": "Canon EOS 5D Mark II",
"lens": null,
"focal_length": "23",
"iso": "50",
"shutter_speed": "30",
"aperture": "9",
"times_viewed": 500,
"rating": 44.2,
"status": 1,
"created_at": "2014-03-08T06:02:13-05:00",
"category": 8,
"location": null,
"latitude": 52.399774296136734,
"longitude": 4.558639526367187
And them some more attributes and photos. I have validated it and that seems ok.
var json = $.getJSON("https://api.500px.com/v1/photos?feature=user&username=bzwemmer&consumer_key=XXX",
function (json) {
console.log(json);
});
var jobj = $.parseJSON(json);
for (var i = 0; i < jobj.length; i++) {
var type = "point";
// Path from json from Firebug = json.responseJSON.photos[0].latitude
var lat = json.responseJSON.photos[0].latitude;
console.log(lat);
if (lat !== null || lat !== "") {
geoobj.photos.push({
lat: photos.lat,
lon: photos.lon,
name: photos.name,
image_url: photos.image_url
});
}
}
I want to select a couple of attributes and put them in another JSON for furter processing. However, with everything I try, I get the message in Firebug that lat = undefined.
I hope someone knows where I am going wrong, because I don't see it anymore.
var jobj = $.parseJSON(json);line.