0
I’m implementing the facebook posts of a particular page on my site and I’m having trouble understanding how to print the following JSON structure:
{
"posts": {
"data": [
{
"created_time": "2017-11-16T19:52:28+0000",
"message": "Teste | JAGUAFRANGOS | A Agência produziu os layouts, vídeo institucional e toda a cobertura do desfile em comemoração ao aniversário de 70 anos de Jaguapitã e aos 25 anos da JAGUAFRANGOS na cidade. ",
"story": "Teste",
"id": "157428127680859_1519494691474189"
}
],
"paging": {
"cursors": {
"before": "Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhOVGMwTWpneE1qYzJPREE0TlRrNkxUWTJPREU1T1Rrek1UazROemMxTXprek1USVBER0ZA3YVY5emRHOXllVjlwWkE4ZA01UVTNOREk0TVRJM05qZA3dPRFU1WHpFMU1UazBPVFEyT1RFME56UXhPRGtQQkhScGJXVUdXZAzNzZAkFFPQZDZD",
"after": "Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhOVGMwTWpneE1qYzJPREE0TlRrNkxUYzVOemM0TWpZAMU9EYzJNVGsyTXpjMk16RVBER0ZA3YVY5emRHOXllVjlwWkE4ZA01UVTNOREk0TVRJM05qZA3dPRFU1WHpFMU1UQXdNemM1TURVM05UTXlNREVQQkhScGJXVUdXZA0lOOWdFPQZDZD"
},
"next": "Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhOVGMwTWpneE1qYzJPREE0TlRrNkxUYzVOemM0TWpZAMU9EYzJNVGsyTXpjMk16RVBER0ZA3YVY5emRHOXllVjlwWkE4ZA01UVTNOREk0TVRJM05qZA3dPRFU1WHpFMU1UQXdNemM1TURVM05UTXlNREVQQkhScGJXVUdXZA0lOOWdFPQZDZD"
}
},
"id": "123456789101112113"
}
I tried this code but could not print on the screen the list of objects:
$(document).ready(function(){
$.getJSON( "posts.txt", function(data) {
console.log('loaded');
var data = []; // create array here
$.each(data.posts, function (index, posts) {
data.push(posts.data); //push values here
});
console.log(data); // see the output here
});
});
What appears on the screen?
– Felipe
Nothing really. It was supposed to appear on the console but still could not get the desired list. Returns me only "[ ]"
– Odair
Is there an error in the console? And you have two variables with the same name
data
– BrTkCa