I´m trying to put JSON-Information into a PHP variable and I´m getting Errors all the time.
This is my Code to make the JSON readable:
header('Content-Type: application/json');
$jsondecode1 = json_decode($json1);
print_r ($jsondecode1);
This is a snippet of the $jsondecode1:
Array
(
[0] => stdClass Object
(
[flightId] => ******
[******] => stdClass Object
(
[******] => ******
[******] => ******
[******] => ******
[******] => ******
[******] => ******
)
Notice: When I echo the jsondecode1 it outputs this:
Array to string conversion in C:\xampp......\simpletest3.php on line 48
So I used print_r().
What I tried to put (for example) [flightId] into a PHP Variable:
$jsondecode1 = json_decode($json1);
$jsondecode2 = $jsondecode1->flightId;
print_r ($jsondecode2);
Output: Notice: Trying to get property 'flightId' of non-object in C:.........\simpletest3.php on line 48
I tried some other codes too, but the Outputs were very similar and I don´t want to make my Question longer than it needs to be.
So, how do I put (for example) the [flightId] into a PHP variable.
Edit:
Solution:
$jsondecode1 = json_decode($json1);
$jsondecode2 = $jsondecode1[0]->flightId;
print_r ($jsondecode2);
Or:
foreach ($jsondecode1 as $data) {
print_r($data->flightId);
}