Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1045

'Malformed UTF-8 characters, possibly incorrectly encoded' in Laravel

$
0
0

I'm using Laravel (a PHP framework) to write a service for mobile and have the data returned in JSON format. In the data result there are some fields encoded in UTF-8.

The following statement

return JsonResponse::create($data); 

returns the error below

InvalidArgumentExceptionHELPMalformed UTF-8 characters, possibly incorrectly encodedOpen: /var/www/html/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php        } catch (\Exception $exception) {            restore_error_handler();            throw $exception;        }        if (JSON_ERROR_NONE !== json_last_error()) {            throw new \InvalidArgumentException($this->transformJsonError());        }

I've changed:

return JsonResponse::create($data);

to

return JsonResponse::create($data, 200, array('Content-Type'=>'application/json; charset=utf-8' ));

but it still isn't working.

How can I fix it?


Viewing all articles
Browse latest Browse all 1045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>