Javascript 如何将JSON.parse放入Promise.all?
我从Riot Games League of Legends API获取了以下代码以检索一批比赛:Javascript 如何将JSON.parse放入Promise.all?,javascript,json,promise,Javascript,Json,Promise,我从Riot Games League of Legends API获取了以下代码以检索一批比赛: const matches = await Promise.all(matchlist.matches.map(function(match){ return qRequest(server, "/match/v3/matches/" + match.gameId); })); 返回值是JSON格式的字符串。因此,匹配最终增强了JSON字符串数组。不过我需要解析JSON,以便匹配的是一个
const matches = await Promise.all(matchlist.matches.map(function(match){
return qRequest(server, "/match/v3/matches/" + match.gameId);
}));
返回值是JSON格式的字符串。因此,匹配
最终增强了JSON字符串数组。不过我需要解析JSON,以便匹配的是一个对象数组
我只是不知道如何将JSON.parse放在这里?您可以应用到匹配项中
let matches = ... ;
matches = matches.map(json => JSON.parse(json));
或者调用JSON.parse
inline:
const matches = await Promise.all(matchlist.matches.map(function(match){
return qRequest(server, "/match/v3/matches/" + match.gameId)
.then(json => JSON.parse(json));
}));
你为什么要使用
Promise.all
,你有多个承诺吗?@MrAlb:OP知道JSON.parse
。他们不知道如何在这里应用它:“我只是不知道如何在这里适应JSON.parse?”@FelixKling是的,你是对的,我投票赞成你的答案;)后来我意识到有可能再次绘制地图,但我认为必须有一种更优雅的方法,而不是绘制两次。第二个看起来不错。