I'm trying to decode json file using json_decode(), with second parameter true after the string of the json that i got from file_get_contents(). Like below.
json_decode(file_get_contents($dir), true);
I already make sure that the directory in file is correct and stored at $dir the json file is below.
{
"must": {
"title": {
"tag": "<!--section title-->",
"content": null,
"with-content": true
},
"class": {
"tag": "<!--section class-->",
"content": null,
"with-content": true
}
}
But when i try to fetch the json file using the script below.
if(is_file_ready($dir)) {
$set = json_decode(file_get_contents($dir), true);
echo file_get_contents($dir);
if(isset($set['must'])) {
foreach($set['must'] as $node) {
echo $node['tag'];
}
}
It shows only the first echo like below, which the echo $node['tag'] shows nothing.
{ "must": { "title": { "tag": "", "content": null, "with-content": true }, "class": { "tag": "", "content": null, "with-content": true } } }
When i change the echo $node['tag'] to print_r($node['tag']) it shows like this.
Array ( [tag] => [content] => [with-content] => 1 ) Array ( [tag] => [content] => [with-content] => 1 )
My question is why the tag returning null and the content too? are <!-- --> is readed as the comment at json same as html? or maybe something that i did wrong?
Thanks for any correction.
