Recently, with help from the Stack Oveflow community, I learned how to work with JSON data that I got from the Google API. So, I thought I had a grasp on how to do roughly the same kind of action with JSON data from Blogger, again using the Google API.
However, it's been driving me crazy. I can't seem to get a handle on how to get at the right level of the array that I need.
What I am trying to do is get a selection of blog posts and then cherry pick out information and display it. Should be straight forward.
Right now my blog has only three test entries. I want to see if I can loop through the array I create from the JSON to display data. If I use this code:
$recentBlog = json_decode(file_get_contents("https://www.googleapis.com/blogger/v3/blogs/xxxxxxxxxxxxxxxxxxxx/posts?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", true));
foreach ($recentBlog as $item)
{
var_dump($item[0]);
}
... then I get data the first item only from the array. This makes sense to me. I looped through the array, but on each call, I only asked for the first item at the 0
position.
So I thought I would do this:
$recentBlog = json_decode(file_get_contents("https://www.googleapis.com/blogger/v3/blogs/xxxxxxxxxxxxxxxxxxxx/posts?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", true));
$count = 0;
foreach ($recentBlog as $item)
{
var_dump($item[$count]);
$count = $count + 1;
}
... but I get the second and third item only. I do not get the first item anymore.
What is wrong with my code?
If it helps, this is Google's documentation about the format of the JSON that I get back.