I have this json structure:
"[{
"nome":["fulano 1","fulano 2","fulano 3","fulano 4"],
"site":["sitefulano1.html","sitefulano2.html.html","sitefulano3.html","sitefulano2.html"]}]"
Gero it this way with php and pdo mysql:
<?php
$valorV1 = count($v1);
for($col = 0; $col <= $valorV1-1; $col++) {
$autores['nome'][] = $v1[$col]['value'];
$autores['site'][] = $v2[$col]['site'];
}
echo json_encode([$autores]);
?>
The problem I want to put the json data on the screen and I can not, does anyone know how to solve it?
I tried some examples that did not work:
function trataResposta(requisicaoAjax) {
if(requisicaoAjax.readyState == 4) {
if(requisicaoAjax.status == 200 || requisicaoAjax.status == 304) {
var dados = requisicaoAjax.responseText;
alert(dados);
//tentei =
var jsonObj = JSON.parse(dados);
for (var i=0; i < jsonObj.length; i++){
alert(jsonObj[i]);
}
for (var i=0; i < autores.dados.length; i++) { //vai passar por todos os objetos dentro do array
document.getElementById('insere_aqui').innerHTML = dados[i]["nome"];
document.getElementById('insere_aqui').innerHTML = dados[i]["site"];
}
}
}
}
When I tried this way the example works but with my json coming from the bank it does nothing!
var Ex01 = {"indice":"valor","nome" : "Silas Stoffel"}
for (var index in dados ) {
alert(index + ': ' + Ex01[index]);
}
Another question is how do I put a name on json like this? In the case book, how do I do this with php and mysql?
{ "livro" :{
"titulo" : "Construindo sites com CSS e (X)HTML",
"autor" : "Maurício",
"site" : "http://livrocss.com.br"
}
}
I was writing an object in the console when I opened the little icon,
Object
nome
:
"fulano1"
site
:
"sitefulano1.html"
__proto__
:
Object
1
:
Object
nome
:
"fulano2"
site
:
"sitefulano2.html"
__proto__
:
Object
2
:
Object
nome
:
"fulano3"
site
:
"sitefulano3.html"
__proto__
:
Object
3
:
Object
nome
:
"fulano4"
site