Javascript 具有相同标记的多个值

Javascript 具有相同标记的多个值,javascript,json,api,Javascript,Json,Api,好的,我有以下代码,它应该搜索城市词典中的某个术语,然后将定义记录到控制台: var xhr = new XMLHttpRequest(); xhr.open("GET", "http://api.urbandictionary.com/v0/define?term=polar%20vortex", true); xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) {

好的,我有以下代码,它应该搜索城市词典中的某个术语,然后将定义记录到控制台:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://api.urbandictionary.com/v0/define?term=polar%20vortex", true);
xhr.onload = function (e) {
  if (xhr.readyState === 4) {
    if (xhr.status === 200) {
      console.log(xhr.responseText);
      var response = JSON.parse(xhr.responseText);
      console.log("Definition: " + response.list.definition);
    } else {
      console.error(xhr.statusText);
    }
  }
};
xhr.onerror = function (e) {
  console.error(xhr.statusText);
};
xhr.send(null);
但是,当我运行代码时,它返回一个值“undefined”。我认为这是因为JSON中的“list”标记下有多个“definition”标记(请看一看)

所以,我的问题是,我如何获得第一个定义并忽略带有“definition”标记的所有其他值


谢谢

此处
响应。列表是一个数组。因此,您只需通过索引访问它:

console.log("Definition: " + response.list[0].definition);

这将给出列表中的第一个定义。

我无法从您提供的链接中看到JSON,您能给出一个返回内容的示例吗?还有,lol@你在拉什么。
这是因为有多个“定义”
否。如果你有多个键,那么你应该得到最后一个键的值。但最有可能的是
list
是一个数组,或者它不是您所认为的数组。向我们展示JSON。。