I'm trying to loop through my nested JSON and print the results but I get the aforementioned error when I try.
<?php
$json = json_decode($orderItems);
foreach ($json as $key) {
?><p>Product: <?php echo $json[$key] -> {'name'}; ?> | Quantity: <?php echo $json[$key] -> {'quantity'}; ?></p><?php
}
?>
print_r($json)
stdClass Object ( [Tom] => stdClass Object ( [name] => Tom [quantity] => 3 ) [Harry] => stdClass Object ( [name] => Harry [quantity] => 1 ) )
$jsonis an object, and not an array, requiring->instead of[]. Please postprint_r($json)so we can see its contents.trueas the second parameter tojson_decode()to force it into an associative array instead of an anonymous object.