$data = ["id" => 10, "text" => 'Hi'];
return $this->asXml($data);
This page contains the following errors:
error on line 37 at column 2: Encoding error
Below is a rendering of the page up to the first error.
<?xml version="1.0" encoding="UTF-8"?>
<response><id>10</id><text></text></response>
<?xml version="1.0" encoding="UTF-8"?>
<response><id>10</id><text>Hi</text></response>
{"id":10,"text":"Hi"}
{"name":"Exception","message":"Syntax
error.","code":4,"type":"yii\\base\\InvalidParamException","file":"путь...\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php","line":132,"stack-trace":["#0
путь...\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php(62): yii\\helpers\\BaseJson::handleJsonError(4)","#1 [internal function]: yii\\helpers\\Json::yii\\helpers\\{closure}(2, 'json_encode(): ...', 'the path...', 64, Array)","#2
путь...\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php(64): json_encode(Array, 320)","#3
путь...\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(89): yii\\helpers\\BaseJson::encode(Array, 320 путь...\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(73): yii\\web\\JsonResponseFormatter->formatJson(Object(yii\\web\\Response)
путь...\\vendor\\yiisoft\\yii2\\web\\Response.php(1041): yii\\web\\JsonResponseFormatter->format(Object(yii\\web\\Response)
путь...\\vendor\\yiisoft\\yii2\\web\\Response.php(337): yii\\web\\Response->prepare(
путь...\\vendor\\yiisoft\\yii2\\base\\Application.php(392): yii\\web\\Response->send(
путь...\\app\\web\\index.php(17): yii\\base\\Application->run()","#9 {main}"]}
This page contains the following errors:
Find more questions by tags Yii
You can do 1251 transfer - Mabel commented on June 9th 19 at 00:55
How it works
$data = ["id" => 10, "text" => 'Hi'];
return $this->asXml($data);
Doesn't work
$data = ["id" => 10, "text" => 'Hello'];
return $this->asXml($data); - Clifton.Treut commented on June 9th 19 at 00:58
Here it must be the encoding, because if you look at the source code for yii\helpers\BaseJson exception of type yii\base\InvalidParamException it is forwarding in case the code is not possible to encode or decode a string - adell17 commented on June 9th 19 at 01:04