r/PHPhelp • u/Jaypeare • Oct 28 '21
Solved Help with JSON_DECODE
Hello together,
I am no professional developer but try to learn more in this field.
At the moment I try to convert a JSON result to a table, sadly I am stuck on the result from JSON_DECODE.
stdClass Object ( [data] => Array ( [0] => stdClass Object ( [type] => transaction [attributes] => stdClass Object ( [amount] => 10.00 [recipient] => [time] => stdClass Object ( [date_iso8601] => 2021-10-28T14:43:57+02:00 [unix] => 1635425037 ) (...) [1] => (...)
If I understand correctly, I can get the [type] = "transaction" over "$data->data", but how do I get for example the "amount"?
This confuses me, because there are class objects in class objects and I was not able to find a solution in the internet oder forums.
Thankful for every help and suggestion!
9
10
u/MerlinTheGerman Oct 28 '21
if you pass
trueas the second argument tojson_decodeyou will get an associative array instead of stdClass objects. See the documentation for json_decode.$decoded = json_decode($data, true);