Javascript 访问JSON数组中的对象时出现问题
我似乎不知道如何让这个代码片段工作。我正在尝试访问此json片段中的“Name”对象。任何帮助都将不胜感激 $document.readyfunction{ $.getJSON'https://query.yahooapis.com/v1/public/yql?q=select%20*%20来自%20yahoo.finance.quotes%20其中%20symbol%20in%20%22AAPL%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',functiondata{ $'demo'。文本数据[0]。名称; }; }; 因此您有data.query.results.quote.name使用以下命令:Javascript 访问JSON数组中的对象时出现问题,javascript,json,Javascript,Json,我似乎不知道如何让这个代码片段工作。我正在尝试访问此json片段中的“Name”对象。任何帮助都将不胜感激 $document.readyfunction{ $.getJSON'https://query.yahooapis.com/v1/public/yql?q=select%20*%20来自%20yahoo.finance.quotes%20其中%20symbol%20in%20%22AAPL%22&format=json&env=store%3A%2F%2Fdatatables.org%
$(document).ready(function () {
$.getJSON('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=', function(data) {
$('#demo').text(data.query.results.quote.Name);
});
});
API调用不返回数组,而是返回JSON对象 尝试:$'demo'.textdata.query.results.quote.Name 返回的数据结构如下所示:
{
"query": {
"count": 1,
"created": "2017-02-13T18:34:12Z",
"lang": "en-us",
"results": {
"quote": {
// other props...
"Name": "Apple Inc.",
// other props...
}
}
}
}
请在问题本身中提供实际JSON的示例。可能有人可以帮助您,但无法访问API url。谢谢!我知道我需要在抓到我想要的东西之前访问每个物体不客气。您可以查看以下内容以供参考:
{
"query": {
"count": 1,
"created": "2017-02-13T18:34:12Z",
"lang": "en-us",
"results": {
"quote": {
// other props...
"Name": "Apple Inc.",
// other props...
}
}
}
}