这是我的代码:
const userIds: string[] = [
// Squall
'226618912320520192',
// Tofu
'249855890381996032',
// Alex
'343201768668266496',
// Jeremy
'754681236236140666',
// Maddo
'711211838305599538',
// Arden
'375573674306306050',
// Neo
'718874307316678698',
// Mytho
'480092510505402380',
// Yuun
'630427600220717067'
];
const fetchData = async() => {
let users: User[] = [];
for (const id in userIds) {
const response = await fetch('https://api.codetabs.com/v1/proxy/?quest=http://hamsterland.herokuapp.com/api/users?id=' + id);
const user: User = await response.json();
users.push(user);
}
}
我得到了错误Unhandled Rejection (SyntaxError): Unexpected end of JSON input。
如果我分别使用每个 Id 的 API,则所有 API 都会返回有效的 JSON。但是,它在循环中不起作用for。
泛舟湖上清波郎朗
梦里花落0921
相关分类