Skip to content Skip to sidebar Skip to footer

Json Data And Manipulating The Content

I am trying to write out the data from this JSON url into li's. The JSON link is https://www.inquicker.com/facility/americas-family-doctors.json

Solution 1:

You can add a test to check if the length of available_times array is > 0 before accessing the first cell.

And then, you can access to when or url properties :

  • available_times[0].when
  • available_times[0].url

Edit : save name.available_times[0] in a temp var and write temp.when or temp.url.

Solution 2:

I have created a JSFidle check this. You to check the data is available in available_times then proceed. if (name.available_times.length){....... ..... ....

$(document).ready(function(){
$.getJSON('https://www.inquicker.com/facility/americas-family-doctors.json',
    function(data){

    $.each(data.schedules, function(i, name){
        times=''if (name.available_times.length){
                times='<ul>'
                times+='<li><a href="'+name.available_times[0].url+'">'+name.available_times[0].when+'</a></li>'
                times+='</ul>'
            }
            else{
               times='<ul><li>No Time Available</li></ul>'                    
            }
        $('#names').append('<li>' + (name.name) + times + '</li>');
    });
});

});

Solution 3:

In the JSON link, some schedules have empty available_times arrays.

And available_times[0] is an object that contains the properties when and url, so you'll have to write name.available_times[0].url

Post a Comment for "Json Data And Manipulating The Content"