My problem is that this JSON is not being parsed by JavaScript or the jQuery API. I am including the code below and a URL where the JSON output is.
This JSON is being parsed in JavaScript as nothing:
//something like this:
alert(data); // gives an object
alert(data.horas[0].hora; // gives undefined
The JSON itself:
{"horas": [{"hora": "13:20","filmes":[{ "tittle": "A Idade do Gelo 3 - Despertar dos Dinossauros VP3D ", "description": "", "image_url": "images/cartazes/img/a_idade_do_gelo_3_despertar_dos_dinossauros.jpg"}]},{"hora": "15:50","filmes":[{ "tittle": "A Idade do Gelo 3 - Despertar dos Dinossauros VP3D ", "description": "", "image_url": "images/cartazes/img/a_idade_do_gelo_3_despertar_dos_dinossauros.jpg"}]},{"hora": "18:00","filmes":[{ "tittle": "A Idade do Gelo 3 - Despertar dos Dinossauros VP3D ", "description": "", "image_url": "images/cartazes/img/a_idade_do_gelo_3_despertar_dos_dinossauros.jpg"}]},{"hora": "21:05","filmes":[{ "tittle": "A Idade do Gelo 3 - Despertar dos Dinossauros VP3D ", "description": "", "image_url": "images/cartazes/img/a_idade_do_gelo_3_despertar_dos_dinossauros.jpg"}]},{"hora": "13:40","filmes":[{ "tittle": "Igor ", "description": "", "image_url": "images/cartazes/img/igor.jpg"}]},{"hora": "16:10","filmes":[{ "tittle": "Igor ", "description": "", "image_url": "images/cartazes/img/igor.jpg"}]},{"hora": "21:30","filmes":[{ "tittle": "Bruno ", "description": "", "image_url": "images/cartazes/img/bruno.jpg"}]},{"hora": "13:00","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "16:30","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "20:30","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "00:15","filmes":[{ "tittle": "O Barco do Rock ", "description": "", "image_url": "images/cartazes/img/o_barco_do_rock.jpg"}]},{"hora": "12:30","filmes":[{ "tittle": "O Barco do Rock ", "description": "", "image_url": "images/cartazes/img/o_barco_do_rock.jpg"}]},{"hora": "15:25","filmes":[{ "tittle": "O Barco do Rock ", "description": "", "image_url": "images/cartazes/img/o_barco_do_rock.jpg"}]},{"hora": "18:20","filmes":[{ "tittle": "O Barco do Rock ", "description": "", "image_url": "images/cartazes/img/o_barco_do_rock.jpg"}]},{"hora": "00:20","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "13:30","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "17:10","filmes":[{ "tittle": "Harry Potter e o príncipe Misterioso ", "description": "", "image_url": "images/cartazes/img/harry_potter_e_o_principe_misterioso.jpg"}]},{"hora": "13:10","filmes":[{ "tittle": "Cinco Minutos de Paz ", "description": "", "image_url": "images/cartazes/img/cinco_minutos_de_paz.jpg"}]},{"hora": "16:00","filmes":[{ "tittle": "Cinco Minutos de Paz ", "description": "", "image_url": "images/cartazes/img/cinco_minutos_de_paz.jpg"}]},{"hora": "18:30","filmes":[{ "tittle": "Cinco Minutos de Paz ", "description": "", "image_url": "images/cartazes/img/cinco_minutos_de_paz.jpg"}]},{"hora": "21:40","filmes":[{ "tittle": "Cinco Minutos de Paz ", "description": "", "image_url": "images/cartazes/img/cinco_minutos_de_paz.jpg"}]},{"hora": "00:00","filmes":[{ "tittle": "A Proposta ", "description": "", "image_url": "images/cartazes/img/a_proposta.jpg"}]},{"hora": "12:50","filmes":[{ "tittle": "A Proposta ", "description": "", "image_url": "images/cartazes/img/a_proposta.jpg"}]},{"hora": "15:40","filmes":[{ "tittle": "A Proposta ", "description": "", "image_url": "images/cartazes/img/a_proposta.jpg"}]},{"hora": "18:10","filmes":[{ "tittle": "A Proposta ", "description": "", "image_url": "images/cartazes/img/a_proposta.jpg"}]}]}
I've run it in JSONLint and it gives "valid JSON"
You can check it out at:
When I call it via $.post
or $.get
in JSON, I always get empty data in the callback. Can anyone explain to me what it is wrong?
Note:
This is not because of the "same origin policy")
Code:
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$.post("http://localhost/getCinema.php", { cinemaid: 'W5'},
function(data){
alert(data);
alert(data.horas[0]);
}
,"json");
alert("fim");
</script>
</head>
<body>
</body>
</html>