Pls how do I retrieve the title from this json usng PHP
{
"kind": "plus#activityFeed",
"etag": "\"U2cYozG4eBioYd-8MEmyk8vsux4/98RQufcXcSAhnognM4kqOBjWygU\"",
"items": [
{
"kind": "plus#activity",
"etag": "\"U2cYozG4eBioYd-8MEmyk8vsux4/AMRVwIlEV6SoJ8ZkMErQKx04FIc\"",
"title": "Reshared post from Jesse Oguntimehin
My post for #GNigeria day 2
The JSON is incomplete so my answer can only be to the snippet that you posted.
The syntax to reach the title field should be -
data.items[0].title
Note that I put items[0]
because items is an array - notated with the square brakets [ ]
. But the first element of that array seems to be an object - so we can continue with dot notation to reach the title
property.
Convert it into a PHP array using json_decode($str,true)
and take a look at the contents - that should be easier to get at.
Use json_decode. Since the items part is an array I presume there are more than 1 items. So you'll have to loop through those.
<?php
$data = json_decode('the json here', true);
foreach ($data['items'] as $item) {
echo $item['title'];
}
?>