1
Good night!
I’m having a problem locating array by square bracket case.
I’m trying to get the data from "Stats". But its only reference is "accountId" or "summonerName". To get the reference of "Stats" need to get the id "participantId" that’s inside the "participantIdentities".
But my problem is I’m not getting the id "participantId".
JSON Base - Example
{
"gameId":1189987226,
"participantIdentities":[
{
"player":{
"summonerName":"Khal Droggo",
"accountId":1595535
},
"participantId":1
},
{
"player":{
"summonerName":"Lefetos",
"accountId":211703728
},
"participantId":2
}
],
"participants":[
{
"stats":{
"champLevel":16,
"participantId":1
},
"participantId":1
},
{
"stats":{
"champLevel":15,
"participantId":2
},
"participantId":2
}
]
}
I’m using javascript language.
function callback(andress, fn){
$.ajax({
url: andress,
type: 'GET',
dataType: 'json',
error: function(){},
success: fn
});
}
function stats(accountId){
callback('https://api.myjson.com/bins/1ew27p', function(retorno) {
var obj = retorno.participantIdentities;
Object.keys(obj).forEach(function(prop) {
if (obj[prop].accountId == accountId) {
document.write(obj[prop].participantId);
}
});
});
}
stats(211703728);
Instead of using foreach should I wear grep. Thank you very much guy, solved my problem!.
– Augusto Junior
A very simple question, how to recover the value within the "player"
participante[0].summonerName
?– Augusto Junior
participante[0].player.summonerName
– NoobSaibot
A doubt if there is no accountId in the JSON base, it will occur an error, how to treat this?
– Augusto Junior