1

I'm calling some JSON (cut short for size reason);

"numExecutors" : 2,
"description" : null,
"jobs" : [
{
  "name" : "Test",
  "url" : "http://www.carlbruiners.com/job/Test/",
  "color" : "blue"
},
{
  "name" : "Test 2",
  "url" : "http://www.carlbruiners.com/job/Test%202/",
  "color" : "blue"
}
]

I need to be able to get at the jobs.name field, but I've tried various loops but I can't get it to work. My Jquery code is;

function getJobs() {
$.jsonp({
  "url": jenkins_url + "/api/json?jsonp=jsoncallback=?",
  "data": {
      "alt": "json-in-script"
  },
  "success": function(data) {
    //alert('Sucess');
    for(var key in data) {
        var value = data[key];
        //alert(value);
    }
  },
  "error": function(e) {
    alert('Failed ' + e);
  }
});
}

1 Answer 1

2

jobs is an array of objects :

object.jobs[0].name

I'm guessing something like :

function getJobs() {
    $.getJSON({
        url : jenkins_url + "/api/json?jsonp=jsoncallback=?",
        data: {alt: "json-in-script" }
    }).done(function(data) {
        $.each(data.jobs, function(idx, val) {
            console.log(val);
        });
    }).fail(function(e) {
        alert('Failed ' + e);
    });
}

And it's asynchronous!

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.