bashir saboori bashir saboori - 3 months ago 12
Javascript Question

access to json Api objects using jquery

I want to get access to json api objects using jquery:

"schedule":{"time":"22:00","days":["Wednesday","Thursday"]}


and i'm using this jquery code to get time data:

jQuery.getJSON("http://api.tvmaze.com/lookup/shows?imdb=" + co + "", function(data) {
jQuery.each(data, function(key, val) {
jQuery('input[name=' + key + ']').val(val);
if (key == "schedule") {
var tim = "";
jQuery.each(data.schedule, function(i, item) {
tim += item.time;
});
jQuery('#schedule_time').val(tim);
}
});


but nothing will show in output!

please help!

"network":{"id":128,"name":"KBS2","country":{"name":"Korea, Republic of","code":"KR","timezone":"Asia/Seoul"}}

Answer
if (key == "schedule") {
    // val == {"time":"22:00","days":["Wednesday","Thursday"]}
    jQuery('#schedule_time').val(val.time);
}

Since you already have access to the result of schedule, you don't need to create another loop. Just access the time directly.