Я пытаюсь получить некоторую информацию из моего объекта JSON и я получаю сообщение об ошибке на моей консоли, говоря:JSON объект из строки не возвращает строку
Uncaught TypeError: Cannot read property 'queue' of undefined".
У меня есть этот 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"
}
}
Я хочу, чтобы получить имя очереди, которое является «rr7323-psp». Вот мой код:
function searchFile (qid, filename) {
var searchUrl = queue_web_services_base + "https://stackoverflow.com/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));
}
Можете ли вы поделиться примером того, как выглядит загрузка 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 "}} –
Объект json выглядит так: Object {qmd_file: Object} qmd_file: Objectfull_path:"/devl/data/queues/psp/rr7323/unicode "mtime:" 2015-05-08T19: 02: 06.000-04: 00 "name:" unicode "queue:" rr7323-psp " –