Skip to content

Commit edaaf8d

Browse files
committed
Updates
1 parent 055efc2 commit edaaf8d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/Json.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,6 @@ private function _arrayToJSONString(array $value,$asObject = false) {
954954

955955
return $arr;
956956
}
957-
private static function _arrayToObj($subVal) {
958-
$subObj = new Json();
959-
960-
foreach ($subVal as $key => $val) {
961-
self::_fixParsed($subObj, $key, $val);
962-
}
963-
964-
return $subObj;
965-
}
966957
private static function _checkArr($subVal, &$parentArr) {
967958
$isIndexed = self::_isIndexedArr($subVal);
968959

@@ -989,9 +980,6 @@ private static function _checkArr($subVal, &$parentArr) {
989980
}
990981
}
991982
$parentArr[] = $subArr;
992-
} else {
993-
// Object inside array
994-
$parentArr[] = self::_arrayToObj($subVal);
995983
}
996984
}
997985
/**
@@ -1171,7 +1159,7 @@ private static function _toCamelCase($attr) {
11711159

11721160
for ($x = 0 ; $x < strlen($attr) ; $x++) {
11731161
$char = $attr[$x];
1174-
1162+
11751163
if (($char == '-' || $char == '_') && $x != 0) {
11761164
$changeNextCharCase = true;
11771165
continue;

tests/JsonXTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@ public function testDecode05() {
325325
$this->assertTrue(gettype($outerArr[0]->get('deep-arr')) == 'array');
326326

327327

328+
}
329+
public function testDecode08() {
330+
$jsonStr = '{"arr":['
331+
. '["hello", {"one":1}, [{"sub-arr":["one", {"hello":"world"}]}]'
332+
. ']'
333+
. ']}';
334+
$decoded = Json::decode($jsonStr);
335+
$this->assertTrue($decoded instanceof Json);
336+
$this->assertEquals($jsonStr, $decoded->toJSONString());
337+
$arr = $decoded->get('arr');
338+
$this->assertTrue(gettype($arr) == 'array');
339+
$this->assertEquals(1, count($arr));
340+
$this->assertEquals('hello',$arr[0][0]);
341+
$subObj = $arr[0][1];
342+
$this->assertTrue($subObj instanceof Json);
343+
$this->assertTrue($subObj->hasKey('one'));
344+
$subArr = $arr[0][2];
345+
$this->assertTrue(gettype($subArr) == 'array');
328346
}
329347
/**
330348
* @test

0 commit comments

Comments
 (0)