I've got some troubles fetching data from JSON array. I'm using node + async + request (and express ofc).
Part of the code :
function(data, callback){
var URL = 'https://'+ server + '.api.pvp.net/api/lol/' + serw + '/v1.3/stats/by-summoner/' + data.id + '/summary?season=SEASON2016&api_key=' + api;
request(URL, function(err, response, body){
if(!err & response.statusCode == 200){
var json = JSON.parse(body);
var assists = json['playerStatSummaries'][0]['aggregatedStats'].totalAssists;
The main problem is that [0] is giving back the first object from array.
{
"playerStatSummaries": [
{
"playerStatSummaryType": "CAP5x5",
"aggregatedStats": {
"totalNeutralMinionsKilled": 2042,
"totalMinionKills": 4317,
"totalChampionKills": 350,
"totalAssists": 417,
"totalTurretsKilled": 36
},
"modifyDate": 1453276061000,
"wins": 20
},
{
"playerStatSummaryType": "CoopVsAI",
"aggregatedStats": {
"totalNeutralMinionsKilled": 446,
"totalMinionKills": 6100,
"totalChampionKills": 1092,
"totalAssists": 761,
"totalTurretsKilled": 116
},
"modifyDate": 1453276061000,
"wins": 80
},
Sometimes the array is a bit different and if player haven't played any "CAP5x5" game, the COOPvsAI is the [0] object.
Any ideas how to fetch data by it's playerStatSummaryType instead of object number in array? Or how to make some kind of bypass that makes null when can't find "CAP5x5" mode? Thanks.