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格式的讷)

阅读 5.2k
1 个回答

这不是源码文件格式的问题,是你从数据库取出的数据有格式问题,可以自己排查一下是哪个字段的数据造成的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题