I have this JSON response from a controller:
{"success":1,"message":"Transaction assigned to customer."}
How do I get the success key to print 1? I have tried
$json = json_decode($assign);
$success = $json->success;
But getting error: Trying to access array offset on value of type null
2
Answers
I have managed to get it working:
in your case as you explained in the comments:
use this one
first decode the json as object,
this lets you to access your value using
$json->success
note: the second parameter of
json_decode
is boolean and named associative which is true by default.and do your logic…
in the Log part,
Log::info
has two parameter first one ismessage
and expected to be a string.and second one is
context
and expected to be an array. just change your$json
into an associative array and send it toLog::info
like this: