I am trying to get some information out of my JSON object and i keep getting an error on my console saying:
Uncaught TypeError: Cannot read property 'queue' of undefined".
I have this json:
{
"qmd_file": {
"queue": "rr7323-psp",
"name": "unicode",
"full_path": "/devl/data/queues/psp/rr7323/unicode",
"mtime": "2015-05-08T19:02:06.000-04:00"
}
}
I want to be able to get queue name which is "rr7323-psp". Here is my code:
function searchFile (qid, filename) {
var searchUrl = queue_web_services_base + "/q/v1/find.json?qgid="
+ encodeURIComponent(qid) + "&filename="
+ encodeURIComponent(filename);
var token = encodeURIComponent(window.bpub.authToken);
$.ajax({
type: "GET",
url: searchUrl,
headers: {'Authorization' : 'Token token="' + token + '"'},
success: function(json) {
var jsonString = JSON.stringify(json);
obj = JSON.parse(jsonString);
console.log(obj.qmd_file[1].queue);
}
});
return searchUrl;
}
self.searchForFile = function() {
var queueGroup = prompt ("Please eneter Queue group" , "")
var fileName = prompt ("Please enter file name: " , "")
console.log(searchFile(queueGroup, fileName));
}