Reputation: 3920
I have to get value from the following Json data
var mydata
prints the following
var mydata ={
"_id": "524d1c36497c4d6f3c56bb84",
"browser": "IE8",
"id": "17",
"jobs": [{
"_id": "52450a0f8d8f5f6eee8bc606",
"id": "34",
"launch": "iuoiu",
"names": "ioiuo",
"params": [{
"oi": "iuoiuo"
}],
"script": "panini-silk-flow"
}],
"mode": "daily",
"os": "Vista 64",
"server": "uuu"
}
currently am getting values
var os =mydata.os// getting Vista 64
var mode =mydata.mode// daily
but how can i get names
from jobs
Upvotes: 1
Views: 62
Reputation: 494
Try this:
$.each(mydata.jobs, function(key, value) {
console.log(key);
console.log(value);
});
Upvotes: 1
Reputation: 8863
If jobs is a list of jobs in the json, you can traverse it:
for(x in mydata.jobs)
console.log(mydata.jobs[x].names);
Upvotes: 1
Reputation: 100195
jobs
is array of objects , and you seem to get item from array of objects, so do:
console.log(mydata.jobs[0].names); //first item from jobs array , i.e. jobs[0]
//or
console.log(mydata.jobs[0]['names']);
Upvotes: 1
Reputation: 388436
Since jobs
is an array, if there is only one job entry then access it via the index 0
mydata.jobs[0].names
If there are more then one job entry then you need to iterate through the list
Upvotes: 1