更新时间:2023-10-30 08:26:46
你可以使用递归
function fetchNextJson(json_url) {
return fetch(json_url, {
method: 'get'
})
.then(function(response) {
return response.json();
})
.then(function(json) {
results.push(json);
return json.Pagination.NextPage.Href
? fetchNextJson(json.Pagination.NextPage.Href)
: results
})
.catch(function(err) {
console.log('error: ' + error);
});
}
var next_json_url = 'http://localhost:3000/one';
var results = [];
fetchNextJson(json_url).then(function(res) {
console.log(res)
})