从 api 调用获取数据时遇到问题
Having issues getting data from api call
大家好,我打了一个 api 电话,得到了我从未遇到过的回复。我的 api 调用是基本的,看起来像
async function getStudents(){
const response = await fetch('url');
const studentData = response.json();
console.log(studentData)
Promise { : "pending" } : "fulfilled" : Object {
students: (25) […] }
这些是我得到的结果,通常我可以做类似 studentData.students
的事情来获取该对象,但似乎没有得到正确的对象。我在搞什么鬼?
使用这样的东西:
async function getStudents(){
fetch('url')
.then(response => response.json())
.then(data => console.log(data));
.catch(error=>console.log(error,"error occured"));
}
大家好,我打了一个 api 电话,得到了我从未遇到过的回复。我的 api 调用是基本的,看起来像
async function getStudents(){
const response = await fetch('url');
const studentData = response.json();
console.log(studentData)
Promise { : "pending" } : "fulfilled" : Object { students: (25) […] }
这些是我得到的结果,通常我可以做类似 studentData.students
的事情来获取该对象,但似乎没有得到正确的对象。我在搞什么鬼?
使用这样的东西:
async function getStudents(){
fetch('url')
.then(response => response.json())
.then(data => console.log(data));
.catch(error=>console.log(error,"error occured"));
}