我正在尝试显示此 JSON 文件中的所有名称,
https://next.json-generator.com/api/json/get/41P1_UhSI https://next.json-generator.com/api/json/get/41P1_UhSI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>testing</title>
</head>
<body>
<script>
const api_url = 'https://next.json-generator.com/api/json/get/41P1_UhSI';
async function getAPI() {
const response = await fetch(api_url);
const data = await response.json();
console.log(Object.values(data.name)); //or console.log(data.name);
}
getAPI();
</script>
</body>
</html>
当我运行此代码时,出现错误:“未定义”。
如果有人能指出我正确的方向,那就太好了,谢谢!
data
不是一个带有 a 的对象name
财产,所以name
其上未定义。
data
is an array含有many对象与name
特性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)