如何使用javascript访问json文件(API)中的元素?

如何使用javascript访问json文件(API)中的元素?,javascript,json,api,Javascript,Json,Api,我试图显示此JSON文件中的所有名称 测试 const api_url='1〕https://next.json-generator.com/api/json/get/41P1_UhSI'; 异步函数getAPI(){ const response=wait fetch(api_url); const data=wait response.json(); console.log(Object.values(data.name));//或console.log(data.name); }

我试图显示此JSON文件中的所有名称


测试
const api_url='1〕https://next.json-generator.com/api/json/get/41P1_UhSI'; 
异步函数getAPI(){
const response=wait fetch(api_url);
const data=wait response.json();
console.log(Object.values(data.name));//或console.log(data.name);
}
getAPI();

数据
不是具有
名称
属性的对象,因此
名称
未在其上定义

数据
是一个数组,包含多个具有
名称
属性的对象。

尝试以下操作:

const api_url = 'https://next.json-generator.com/api/json/get/41P1_UhSI'  
async function getAPI() {   
  await fetch(api_url)
    .then((response) => {
      return response.json();
    })
    .then((data) => {
      data.map(it => 
      console.log(it.name))
    }); 
} 
getAPI();