Its probably some non UTF-8 string in your database.
When the Response::json()
tries to run - it fails because of non UTF8.
You need to cycle through your array and run utf8_enconde()
on all the results before passing it to Response::json()
Вопрос
I'm trying to send a JSON Response from the server by passing an array to Response::json() but I keep getting the UTF-8 Invalid Argument in vendor\laravel\ ... \jsonReponse.php At line 49
public function getAllForInbox() {
$conn = SqlServerPdo::connect();
$query = "Some Query";
$statement = $conn->prepare($query);
$success = $statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
SqlServerPdo::disconnect();
return Response::json($result);
}
Everything else works fine. I did a var_dump on $result. IS an array containing arrays of data. Each array being a row from the result.
The thing is .... It was working perfectly.... then I ran Composer Update ... and now it doesn't work anymore o.O ... could it be some error on the vendor/laravel folder???
In fact, I have a local development server running, and it works just fine, when I upload to the server currently hosting the App, it doesn't... could it be PHP???
this is and example $result var dump
array(10) {
[0]=>
array(6) {
["numint"]=>
string(1) "1"
["name"]=>
string(15) "Sistel Helpdesk"
["priority"]=>
string(1) "0"
["assignation"]=>
string(0) ""
["tickets_open"]=>
string(1) "1"
["tickets_with_conv"]=>
string(1) "0"
}
...
And 9 other results
Решение
Its probably some non UTF-8 string in your database.
When the Response::json()
tries to run - it fails because of non UTF8.
You need to cycle through your array and run utf8_enconde()
on all the results before passing it to Response::json()