mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Release fix from SilverFire
This commit is contained in:
@ -132,9 +132,7 @@ class BaseJson
|
||||
*/
|
||||
protected static function processData($data, &$expressions, $expPrefix)
|
||||
{
|
||||
if ($data instanceof \Traversable) {
|
||||
return $data;
|
||||
} elseif (is_object($data)) {
|
||||
if (is_object($data)) {
|
||||
if ($data instanceof JsExpression) {
|
||||
$token = "!{[$expPrefix=" . count($expressions) . ']}!';
|
||||
$expressions['"' . $token . '"'] = $data->expression;
|
||||
@ -144,6 +142,8 @@ class BaseJson
|
||||
$data = $data->jsonSerialize();
|
||||
} elseif ($data instanceof Arrayable) {
|
||||
$data = $data->toArray();
|
||||
} elseif ($data instanceof \SimpleXMLElement) {
|
||||
$data = (array) $data;
|
||||
} else {
|
||||
$result = [];
|
||||
foreach ($data as $name => $value) {
|
||||
|
@ -7,6 +7,7 @@ use yii\helpers\BaseJson;
|
||||
use yii\helpers\Json;
|
||||
use yiiunit\TestCase;
|
||||
use yii\web\JsExpression;
|
||||
use yiiunit\framework\web\Post;
|
||||
|
||||
/**
|
||||
* @group helpers
|
||||
@ -113,6 +114,12 @@ class JsonTest extends TestCase
|
||||
|
||||
$document = simplexml_load_string($xml);
|
||||
$this->assertSame('{"apiKey":"ieu2iqw4o","methodProperties":{"FindByString":"Kiev"}}', Json::encode($document));
|
||||
|
||||
$postsStack = new \SplStack();
|
||||
$postsStack->push(new Post(915, 'record1'));
|
||||
$postsStack->push(new Post(456, 'record2'));
|
||||
|
||||
$this->assertSame('{"1":{"id":456,"title":"record2"},"0":{"id":915,"title":"record1"}}', Json::encode($postsStack));
|
||||
}
|
||||
|
||||
public function testDecode()
|
||||
|
Reference in New Issue
Block a user