1
I have json that I created and wanted to dynamically take the array and objects inside it
var json = [
{'PHP':
[
{'aula1':
[
'txt','O PHP é uma linguagem ...',
'img','caminho','descrição'
]
},
{'aula2':
[
'txt','Nessa aula aprenderemos ...',
'btn','Download','caminho','nome'
]
}
]
},
{'HTML':
[
{'aula1':
[
'txt','HTML significa linguagem ...'
]
},
{'aula2':
[
'txt','Nessa aula aprenderemos ...',
'btn','Download','caminho','nome'
]
}
]
}
]
something like:
var materia = 'PHP'
var numMateria = 0
var aula = 'aula1'
var numAula = 0
for(i = 0; i < json.[indexMateria].materia[indexAula].aula.length; i++) {
if(json.[indexMateria].materia[indexAula].aula[i] == 'txt') {
document.write('<p>' + json.[indexMateria].materia[indexAula].aula[i+1] + '</p>')
i += 1
} else if(json.[indexMateria].materia[indexAula].aula[i] == 'img') {
document.write('<img src="' + json.[indexMateria].materia[indexAula].aula[i+1] + '" alt="' + json.[indexMateria].materia[indexAula].aula[i+2] + '">')
i += 2
}
}
Only when I wear json[indexMateria].materia
he searches for an object materia
instead of using the variable materia
Does anyone have any idea what to do? It’s okay to change json or use frameworks
Exactly what you want to seek?
– Felipe Duarte
the array within the class objects
– Costamilam