response.json()
возвращает еще одно обещание [1], поэтому вам нужно будет дважды вызвать Promise.all
, например:
Promise.all(requests)
.then(responses => Promise.all(responses.map(r => r.json())))
.then(jsonObjects => /* ... */);
Для удобства чтения вы можете ввести вспомогательную функцию
Promise.all(requests)
.then(toJSON)
.then(jsonObjects => /* ... */);
function toJSON(responses) {
if (!Array.isArray(responses)) {
// also handle the non array case
responses = [responses];
}
return Promise.all(responses.map(response => response.json()));
}
Если вам нужно сохранить ответ (состояние):
function resolveJSON(responses) {
return Promise.all(
responses.map(response => response.json()
// will return an object with keys "response" and "json"
.then(json => { response, json }))
);
}
[1] https://developer.mozilla.org/en-US/docs/Web/API/Body/json