无法在变量中存储JSON
我无法在变量中存储JSON。当我调用getIndividualMatchJSONObjHelper函数时,json变量本身会打印出来,但变量外部不会存储任何内容。如何在matchParticipantData.specificParticipantData中正确存储JSON变量无法在变量中存储JSON,json,node.js,async.js,Json,Node.js,Async.js,我无法在变量中存储JSON。当我调用getIndividualMatchJSONObjHelper函数时,json变量本身会打印出来,但变量外部不会存储任何内容。如何在matchParticipantData.specificParticipantData中正确存储JSON变量 function getIndividualMatchJSONObj(matchData) { var matchParticipantData = { specificParticipantDat
function getIndividualMatchJSONObj(matchData) {
var matchParticipantData = {
specificParticipantData: [numberOfGames]
};
for (var i = 0; i < numberOfGames; i++) {
getIndividualMatchJSONObjHelper(matchData, matchParticipantData, i, function(err, json) {
matchParticipantData.specificParticipantData[i] = json;
});
}
return matchParticipantData;
}
function getIndividualMatchJSONObjHelper(matchData, matchParticipantData, indexIter, callback) {
var individualMatchURL = 'https://na1.api.riotgames.com/lol/match/v3/matches/' + matchData.matchID[indexIter] + '?api_key=' + API_KEY;
var jsonFinal;
async.waterfall([
function (callback) {
request(individualMatchURL, function (err, response, body) {
if (err)
return callback(err);
if (response.statusCode != 200)
return callback(new Error('Status code was ' + response.statusCode));
var json = JSON.parse(body);
for (var j = 0; j < 10; j++) {
if (matchData.championID[indexIter] == json['participants'][j].championId) {
return callback(null, json['participants'][j]);
}
}
});
}
], callback);
函数getIndividualMatchJSONObj(matchData){
var matchParticipantData={
具体参与者数据:[游戏数量]
};
对于(var i=0;i}在getIndividualMatchJSONObj中
for (var i = 0; i < numberOfGames; i++) {
getIndividualMatchJSONObjHelper(matchData, matchParticipantData, i, function(err, json) {
matchParticipantData.specificParticipantData[i] = json;
});
}
return matchParticipantData;
用法:
var data = test();
console.log(data);
test(function(data) {
console.log(data);
});
回调:
function test(callback) {
callback("test");
}
用法:
var data = test();
console.log(data);
test(function(data) {
console.log(data);
});