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'],
]);
答案 0 :(得分:2)
您可以像这样传递json_encode选项
$this->set('_jsonOptions', JSON_NUMERIC_CHECK);
$this->set('_serialize', ['success', 'code', 'response', 'errors']);
https://book.cakephp.org/3/en/views/json-and-xml-views.html#creating-json-views