I want to include a php file in one another and decode the JSON that I get.
Here´s my code:
<?php
$jsonstring = include('php/get_recipe_byID.php');
$obj = json_decode($jsonstring);
print_r($obj->Data);
?>
$jsonstring is
{"Data":{"Recipes":{"Recipe_10":{"ID":"10","TITLE":"Pferde\u00e4pfel","TEXT":"Sammeln und Essen","COUNT_PERSONS":"4","DURATION":"60","USER_ID":"1","DATE":"1000-01-01 00:00:00"}}},"Message":null,"Code":200}
The error I get is
Notice: Trying to get property of non-object in /var/www/recipe_search.php on line 118
which is the row with print_r($obj->Data);
How can I handle that?
It is because you include the file and not use the file directly. You should be using file_get_contents instead.
However!
I have some times had issues with using json_decode and its turning into objects, and i prefer using its associative array options instead. Try using