lumen utf8 编码报错
Whoops, looks like something went wrong.
(1/1) InvalidArgumentException
Malformed UTF-8 characters, possibly incorrectly encoded
in JsonResponse.php (line 71)
控制器
$this->validate($request, [
"id" => "required|numeric"
]);
$newId = $request->input('id');
$userInfo = Auth::user();
$userId = $userInfo->id;
$community = $userInfo->have_doorID;
$companyId = $userInfo->companyID;
$re = NewNotice::getAllNewsList($userId,$newId,$companyId,$community);
if (!$re) return $this->output_error('NOTICE_ERROR');
for ($i=0;$i<count($re);$i++){
$array[$i]['id'] = $re[$i]->id;
$array[$i]['title'] = $re[$i]->title;
$content = $re[$i]->content;
$array[$i]['content'] = substr($content,0,32);
$array[$i]['time'] = $re[$i]->created_at;
$array[$i]['url'] = $re[$i]->url;
$array[$i]['style'] = $re[$i]->style;
$array[$i]['type'] = $re[$i]->type;
$array[$i]['name'] = $re[$i]->applicant;
$array[$i]['img'] = $re[$i]->img;
$array[$i]['plot_name'] = $re[$i]->destination;
$array[$i]['start_time'] = $re[$i]->start_time;
$array[$i]['end_time'] = $re[$i]->end_time;
}
return $this->output_data($array);
数据模型
public static function getAllNewsList($userId,$newId,$companyId,$communityId){
$communityArr = explode(",",$communityId);
$sql = "SELECT * FROM notices";
$where = " WHERE addressee= :userId";
$array = array();
$array['userId'] = $userId;
if($newId){
$where .= " AND id > :newId";
$array['newId']=$newId;
}
if($companyId){
$where .= " OR addressee= :companyId";
$array['companyId']=$companyId;
}
if($communityId){
for ($i=0;$i<count($communityArr);$i++){
$where .= " OR addressee= $communityArr[$i]";
}
}
$query = $sql.$where;
$res = DB::select($query, $array);
return $res;
}
控制器return 出来的值报畸形UTF-8字符 请问是什么原因造成的啊 (两个文件都utf8格式的讷)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是源码文件格式的问题,是你从数据库取出的数据有格式问题,可以自己排查一下是哪个字段的数据造成的