Javascript 我保证一切都会好起来的

Javascript 我保证一切都会好起来的,javascript,node.js,express,promise,Javascript,Node.js,Express,Promise,我正在尝试循环10场传奇联盟的比赛,对于每一场比赛,调用另一个api来获取比赛细节。到目前为止,我有一个如下设置的函数: function getAllMatchData(ids) { const promises = []; _.take(ids, 1).forEach(id => { const promise = fetch(`https://na1.api.riotgames.com/lol/match/v4/matches/${id}`, {

我正在尝试循环10场传奇联盟的比赛,对于每一场比赛,调用另一个api来获取比赛细节。到目前为止,我有一个如下设置的函数:

function getAllMatchData(ids) {
    const promises = [];
    _.take(ids, 1).forEach(id => {
        const promise = fetch(`https://na1.api.riotgames.com/lol/match/v4/matches/${id}`, {
            headers: {"X-Riot-Token": token}})
        promises.push(promise);
    })
    return Promise.all(promises);
}
Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [Gunzip], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'https://na1.api.riotgames.com/lol/match/v4/matches/3556728982',
      status: 200,
      statusText: 'OK',
      headers: [Headers],
      counter: 0
    }
  }
由于api返回100个匹配项,我只取前10个,然后用它们创建一个承诺数组。然后我这样做以获得结果:

getAllMatchData(_.map(data['matches'], 'gameId')).then(results => {
     console.log(results);
}).catch(error => {
     console.log(error);
})
但是结果的控制台日志中没有任何json数据。它打印一组对象,如下所示:

function getAllMatchData(ids) {
    const promises = [];
    _.take(ids, 1).forEach(id => {
        const promise = fetch(`https://na1.api.riotgames.com/lol/match/v4/matches/${id}`, {
            headers: {"X-Riot-Token": token}})
        promises.push(promise);
    })
    return Promise.all(promises);
}
Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [Gunzip], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'https://na1.api.riotgames.com/lol/match/v4/matches/3556728982',
      status: 200,
      statusText: 'OK',
      headers: [Headers],
      counter: 0
    }
  }

我不确定JSON数据响应在哪里。

使用fetch,您需要使用收到的响应类型解析响应

const promise=fetch(`https://na1.api.riotgames.com/lol/match/v4/matches/${id}`{
标题:{“X-Riot-Token”:Token}})。然后(res=>res.json())
在你的例子中,它是json。因此,只需调用
res.json()
即可