0
I have a question about JSON.
I need to pull the information inside the array. However it does not have the reference that would be the name of Champion that is within the date that I need to locate, the only thing it possesses is the key.
Base of JSON:
{
"type":"champion",
"format":"standAloneComplex",
"version":"7.18.1",
"data":{
"Aatrox":{
"id":"Aatrox",
"key":"266",
"name":"Aatrox",
"title":"a Espada Darkin",
"image":{
"full":"Aatrox.png",
"sprite":"champion0.png",
"group":"champion",
"x":0,
"y":0,
"w":48,
"h":48
}
},
"Viktor":{
"id":"Viktor",
"key":"112",
"name":"Viktor",
"title":"o Arauto das Máquinas",
"image":{
"full":"Viktor.png",
"sprite":"champion4.png",
"group":"champion",
"x":0,
"y":0,
"w":48,
"h":48
}
}
}
}
I am using javascript language with jquery. When pulling the data does not locate. How to resolve this?
$.ajax({
type:'GET',
url: 'http://ddragon.leagueoflegends.com/cdn/7.18.1/data/pt_BR/champion.json',
dataType:'json',
success: function(data) {
var arr = [];
arr.push(data);
for(var i=0; i<arr.length; i++) {
if(arr[i].data.key === 266) {
console.log(arr[i].data.name);
}
}
},
error: function(data) { }
});
With your help you solved my problem! But when I create a function, the variable id does not recognize. Just to warn not know much in javascript, I am in the learning phase.
– Augusto Junior
I’m here kicking my celebro to understand how to put the variable inside Function. I’m not getting the logic.
– Augusto Junior
@Augustojunior what is the code that needs this variable? Is it a function? Put a jsFiddle with the code here to see.
– Sergio