I have the folowing format of json:
[
{
"title": "title will be here",
"teaser": "teaser will be here...",
"date": ["2015-11-19T00:00:00"]
}
]
and the php to read the json:
$json = file_get_contents( "news.json" );
$data = json_decode( $json );
json_decode( json_encode( $data ), true );
foreach ( $data as $object ):
echo $object->{'title'};
echo $object->{'teaser'};
echo $object->{'date'};
endforeach;
the code returns title and teaser but not the date, what should i do to return the date correctly?
datevalue is an array; you should see a warningcannot convert Array to string.$data = json_decode($json, true)? and'date'is an array. you can't echo out an array.$object->date[0], maybe.