Trying to retreive some JSON from a server which looks like the following
json = {"posts":[{
"post":{
"title" : "foo",
}
},
{
"post":{
"title" : "bar",
}
},
]}
And I am trying to loop over like
for(var i = 0; i < json.length; i++) {
var obj = json[i];
console.log(obj.posts.post.title);
}
Which doesn't work.
And I've tried
var totalMessages = Object.keys(json.posts).length;
for(var i = 0; i < totalMessages; i++) {
console.log(json.posts.post.title);
}
Which also doesn't work
How can I loop through the above json and log the titles?
Thanks