可能编码不正确,UTF-8 字符格式不正确



我正在尝试获取 laravel 中的记录,然后它会给我以下错误。

格式错误的 UTF-8 字符,可能编码不正确

这是我的代码

$Login = DB::table('usermaster')
        ->where('Email', $uname)
        ->where('Password', md5($password))
        ->get();
    return response()->json($Login);

在我的 laravel 查询中,我使用以下代码,因此它会给出这种类型的错误......

格式错误的 UTF-8 字符,可能编码不正确

$BvoData = DB::table('test1')->select('test1.*')
        ->where("test1.Id", "".$id."")
        ->first();
$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get(); 
$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();
return response()->json($BvoData);

但是我将通过执行以下代码来解决此错误...

$BvoData = DB::table('test1')->select('test1.*')
        ->where("test1.Id", "".$id."")
        ->first();
$BvoData = (array)  $BvoData;
$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get(); 
$BvoData["temp1"] = json_decode(json_encode($BvoData["temp1"]), True);

$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();
$BvoData["temp2"] = json_decode(json_encode($BvoData["temp2"]), True);
return response()->json($BvoData);

通过使用json_decode和json_encode我解决了我的问题......

最新更新