json_decode won't work

Hello friends.
In my database I have table named “groups” and inside this table, among the others, I have column named “permissions” with a value {“admin”: 1}. Now, in my PHP code, when I use json_decode function, nothing happens, function doesn’t work and it won’t print anything. This is my code:

[php]

$group = $this->_db->get(‘groups’, array(‘id’, ‘=’, $this->data()->protyp));
$permissions = json_decode($group->first()->permissions, true);
print_r($permissions);
[/php]

When I echo $permissions = $group->first()->permissions; (without json_decode), everything works, but when I use json_decode, nothing happens. I use PHP 5.6. Can anyone help me? Thanks in advance

Maybe this will help

You use json_decode to go from Javascript to PHP:

[php]/* Makes it so we don’t have to decode the json coming from JavaScript */
header(‘Content-type: application/json’);[/php]

Put that at the top and you don’t have to use json_decode all the time.

and json_encode to go from PHP to Javascript:
[php]
function errorOutput($output, $code = 500) {
http_response_code($code);
echo json_encode($output);
}
/*

  • If everything validates OK then send success message to Ajax/JavaScript */
    function output($output) {
    http_response_code(200);
    echo json_encode($output);
    }[/php]

maybe showing a little bit of your javascript code would also help, for it might shed light on the problem?

Problem is solved, it was stupid mistake, instead of {“admin”: 1} I typed {“admin: 1”}. Stupid mistake but I wanted to blow my brain out. Thanks for reply.

Sponsor our Newsletter | Privacy Policy | Terms of Service