问题描述:
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