Class to create json

0

I made this class to create a JSON to return in my Web Service , but not working, would anyone know why?

Class Useful

<?php

class Uteis {
    public static function criarjson($mensagem,$value){

       $json_str = '{"autenticado":$value, "mensagem":$mensagem}';
       $json = json_decode($json_str);
       return json_encode($json);   

    }
}
?>

Index.php

$app->post('/login',function(Request $request,Response $response){
    $allquery = $request->getQueryParams();
    $user = new Usuario();
    $sql = new Sql();
    $autenticado = $user->login($allquery['login'],$allquery['senha']);
    if ($autenticado) {
        $response = Uteis::criarjson("AA",true);
    }else{
        $response = Uteis::criarjson("Erro ao autenticar",false);
    }
    return $response;
});
$app->run();
    
asked by anonymous 03.12.2017 / 19:49

1 answer

1

Your array looks like this:

<?php

  class Uteis {
    public static function criarjson($mensagem,$value){

      $json_str  = array(
                        "autenticado" => $value,
                        "mensagem"    => $mensagem
                    );
       echo json_encode($json_str );   

    }
}
?>
    
03.12.2017 / 20:03