Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在变量中存储JSON_Json_Node.js_Async.js - Fatal编程技术网

无法在变量中存储JSON

无法在变量中存储JSON,json,node.js,async.js,Json,Node.js,Async.js,我无法在变量中存储JSON。当我调用getIndividualMatchJSONObjHelper函数时,json变量本身会打印出来,但变量外部不会存储任何内容。如何在matchParticipantData.specificParticipantData中正确存储JSON变量 function getIndividualMatchJSONObj(matchData) { var matchParticipantData = { specificParticipantDat

我无法在变量中存储JSON。当我调用getIndividualMatchJSONObjHelper函数时,json变量本身会打印出来,但变量外部不会存储任何内容。如何在matchParticipantData.specificParticipantData中正确存储JSON变量

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);
});