InvalidArgumentException:格式错误的UTF-8字符,可能在文件中编码不正确-Laraval

问题描述

返回Std类类型对象时,显示错误。我正在使用PHP 7和Laravel 7.0

错误从JsonResponse.php的setData函数返回(Illuminate \ Http) 使用DEFAULT_ENCODING_OPTIONS = 15的setData函数。这就是该问题的原因

enter image description here

我无法解决此问题,但是我尝试将JsonResponse setData方法$this->encodingOptions更改为JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_IGNORE

现在,错误已解决。但是我需要另一种解决方法。

public function setData($data = [])
{
    $this->original = $data;

    if ($data instanceof Jsonable) {
        $this->data = $data->toJson($this->encodingOptions);
        //$this->data = json_encode($data->jsonSerialize(),JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_IGNORE);  // LINE NO: 01

    } elseif ($data instanceof JsonSerializable) {

        $this->data = json_encode($data->jsonSerialize(),$this->encodingOptions);
        //$this->data = json_encode($data->jsonSerialize(),$this->encodingOptions);  // LINE NO: 02

    } elseif ($data instanceof Arrayable) {

        $this->data = json_encode($data->toArray(),$this->encodingOptions);
    } else {
        $this->data = json_encode($data,$this->encodingOptions);
        //$this->data = json_encode($data,JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_IGNORE);  // LINE NO: 03

    }

    if (!$this->hasValidJson(json_last_error())) {
        throw new InvalidArgumentException(json_last_error_msg());
    }

    return $this->update();
}

取消注释行1,2,3错误已解决! 我需要另一种方法来解决此问题。因为在运行后,composer安装了该更改,因此... 这是我检索json的一部分

 {  "cart": [
        {
            "id": "a9756db0d79a11ea96c7cf86f7c6e0ee","book_id": "81180660d2ed11eaa5299b806f9af290","user_customer_user_id": "437a2b60d23611ea942efb15df219288","status": "ACTIVE","book": {
                "id": "81180660d2ed11eaa5299b806f9af290","user_admin_user_id": "9c80e8006d5b11e9bb9835ecbe2a229e","publisher_id": "7b0d3ac0d6ec11ea8cb15deb159804b0","printed_price": 319,"purchase_link": "no","description": "no","pages": -1,"rating_value": 0,"file_type": "e-pub","revenue_split_type": "OP","book_authors": [
                    {
                        "user_id": "a6d99c206d5b11e9af1a4bbf4f149b08","reference_no": "XN87397509","description": null,"search_tags": null,"bank_name": null,"account_number": null,"user": {
                            "id": "a6d99c206d5b11e9af1a4bbf4f149b08","name": "Anton Dias","email": "Anton Dias@email.com","country_code": null,"contact_number": null,"status": "ACTIVE"
                        }
                    },{
                        "user_id": "aa45c0206d5b11e9941ae50cf510f0f3","reference_no": "EB26705547","user": {
                            "id": "aa45c0206d5b11e9941ae50cf510f0f3","name": "K.G.Karunathilake","email": "K.G.Karunathilake@email.com","status": "ACTIVE"
                        }
                    }
                ],"book_images": [
                    {
                        "book_id": "81180660d2ed11eaa5299b806f9af290","type": "LIST","size": 0.67
                    },{
                        "book_id": "81180660d2ed11eaa5299b806f9af290","type": "PROFILE","size": 0.67
                    }
                ],"promotions": []
            }
        }
]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...