0

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"}}
2
  • provide full code. where you get key? Commented Aug 22, 2016 at 15:47
  • I get the key from the top json code "schedule". Commented Aug 22, 2016 at 15:59

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

2 Comments

@bashirsaboori You can access the timezone in the second object you posted using network.country.timezone
@bashirsaboori it may be helpful if you post a new question. It's difficult to determine the issue without more context, which is difficult to establish in comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.