问题描述:
Warning: json_encode() expects parameter 2 to be long, string given in app\controller\BaseController.php on line 80
出错部分代码:
function jsonResult( $state = 0, $message = "", $data = array(), $total = 0, $pageSize = 0 )
{
return json_encode(array('state' => $state, 'message' => $message, 'data' => $data, 'total' => $total, 'pageSize' => $pageSize), JSON_UNESCAPED_UNICODE);
}
define ('JSON_UNESCAPED_UNICODE', 256);
- 1
解决方案:
将“JSON_UNESCAPED_UNICODE”替换成256。 function jsonResult( $state = 0, $message = "", $data = array(), $total = 0, $pageSize = 0 )
{
/**
* define ('JSON_UNESCAPED_UNICODE', 256);
* 将“JSON_UNESCAPED_UNICODE”替换成256,避免出现如下警告(版本<5.4):
* json_encode() expects parameter 2 to be long, string given in
*/
return json_encode(array('state' => $state, 'message' => $message, 'data' => $data, 'total' => $total, 'pageSize' => $pageSize), 256);
}
- 5
- 6
- 7
- 8
- 9

![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)

















