CakePHP响应数作为字符串

CakePHP响应数作为字符串,cakephp,Cakephp,CakePHP在json响应中将数字序列化为字符串,如{“foo”:“123”},它应该是{“foo”:123}有任何配置吗 $stm = "select * from clients"; $response = $conn->execute($stm)->fetchAll('assoc'); $this->set([ 'success' => $success, 'code' => $code,

CakePHP在json响应中将数字序列化为字符串,如{“foo”:“123”},它应该是{“foo”:123}有任何配置吗

    $stm = "select * from clients";
    $response = $conn->execute($stm)->fetchAll('assoc');

    $this->set([
        'success' => $success,
        'code' => $code,
        'response' => $response,
        'errors' => $errors,
        '_serialize' => ['success', 'code', 'response', 'errors'],
    ]);

您可以像这样传递json_编码选项

$this->set('_jsonOptions', JSON_NUMERIC_CHECK);
$this->set('_serialize', ['success', 'code', 'response', 'errors']);

您可以像这样传递json\u编码选项

$this->set('_jsonOptions', JSON_NUMERIC_CHECK);
$this->set('_serialize', ['success', 'code', 'response', 'errors']);

请检查您的数据库、其varchar或INTA并使用$this->Clients->find('all')//使用model@RiteshParyali使用模型可以很好地工作,但是我们有一些复杂的自定义查询需要使用fetchAll('assoc')!在数据库中是int!如果我使用这个函数json_encode($data,json_NUMERIC_CHECK),它可以工作,但可能在cake中有一些配置可以在_serialize中实现这一点!请检查您的数据库,其varchar或int并使用$this->Clients->find('all')//使用model@RiteshParyali使用模型可以很好地工作,但是我们有一些复杂的自定义查询需要使用fetchAll('assoc')!在数据库中是int!如果我使用这个函数json_encode($data,json_NUMERIC_CHECK),它可以工作,但可能在cake中有一些配置可以在_serialize中实现这一点!