I am quite confused with JSON, I can easily take first level arrays values, but having problem with subs.
I am using $.getJSON and code is
$.getJSON('http://www.authenticjobs.com/api/?api_key=4c4f1d5934d66ca872dfa2a0cfd3a20b&method=aj.jobs.search&perpage=3&format=json&callback=?', function(data) {
var listings = "";
$.each(data.listings.listing, function(index, listing) {
listings += "<li><strong>" + listing.company.name + "</strong> needs a <a href='" + listing.url + "'>" + listing.title + "</a>";
if (listing.location != "") {
listings += " in " + listing.location;
}
listings += "</li>";
});
$("#authentic-jobs ul").append(listings);
});
Visual data is here: http://cloud.ignatynikulin.com/2v0F2p2x111r0X3k4441
I can’t get company location name.
I ve tried listing.company.location.name but it’s not working and also don’t make any sense.
Thank you!
Answer will be (thank you GregL):
Since listing.company.location is a nested object (visualised by the
{} in the picture you attached), so you just want to check if the
object is not something like undefined, null or similar (what are
called “falsey values” in Javascript).
I think I created a jsFiddle that works here.
The key is to use: