mirror of
https://github.com/EFTEC/Services_JSON.git
synced 2026-08-19 01:52:40 +00:00
2.5
This commit is contained in:
@@ -116,6 +116,8 @@ var_dump(Services_JSON::encode($obj)); // encode an object
|
||||
|
||||
|
||||
## Changelog
|
||||
* 2.5
|
||||
* now allows "@" and "." for key values.
|
||||
* 2.4
|
||||
* update requirements to php 7.4
|
||||
* added more type hinting (type validation)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection ForgottenDebugOutputInspection */
|
||||
|
||||
use eftec\ServicesJson\Services_JSON;
|
||||
include '../vendor/autoload.php';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection ForgottenDebugOutputInspection */
|
||||
|
||||
use eftec\ServicesJson\Services_JSON;
|
||||
|
||||
@@ -9,12 +9,27 @@ include '../vendor/autoload.php';
|
||||
|
||||
$json='{hello:{a:2,b:3},world:[1,2,3,"aaa","bbbb"]}';
|
||||
|
||||
echo "<h1>Original:</h1><pre>$json</pre><br>";
|
||||
|
||||
echo "Decode as stdclass:<br>";
|
||||
echo "<h1>Decode as stdclass:</h1>";
|
||||
echo "<pre>";
|
||||
var_dump(Services_JSON::decode($json));
|
||||
echo "</pre>";
|
||||
echo "Decode as array:<br>";
|
||||
echo "<h1>Decode as array:</h1>";
|
||||
echo "<pre>";
|
||||
var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY));
|
||||
echo "</pre>";
|
||||
|
||||
$json='hello.world:{a:2,b:3},hello@world:[1,2,3,"aaa","bbbb"]';
|
||||
|
||||
echo "<h1>Original (.@ and missing {} or [] in root):</h1><pre>$json</pre><br>";
|
||||
|
||||
echo "<h1>Decode as stdclass:</h1>";
|
||||
echo "<pre>";
|
||||
var_dump(Services_JSON::decode($json,Services_JSON::DECODE_FIX_ROOT));
|
||||
echo "</pre>";
|
||||
echo "<h1>Decode as array:</h1>";
|
||||
echo "<pre>";
|
||||
var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY|Services_JSON::DECODE_FIX_ROOT));
|
||||
echo "</pre>";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection ForgottenDebugOutputInspection */
|
||||
|
||||
use eftec\ServicesJson\Services_JSON;
|
||||
|
||||
|
||||
@@ -663,7 +663,7 @@ class Services_JSON
|
||||
} else {
|
||||
$obj->$key = $val;
|
||||
}
|
||||
} /** @noinspection NotOptimalRegularExpressionsInspection */ elseif (preg_match('/^\s*(\w+)\s*:/Ui', $slice, $parts)) {
|
||||
} /** @noinspection NotOptimalRegularExpressionsInspection */ elseif (preg_match('/^\s*([a-z.@A-Z0-9_]+)\s*:/Ui', $slice, $parts)) {
|
||||
// name:value pair, where name is unquoted
|
||||
$key = $parts[1];
|
||||
$val = self::decode2(trim(substr($slice, strlen($parts[0])), ", \t\n\r\0\x0B"));
|
||||
|
||||
@@ -55,6 +55,11 @@ final class FirstTest extends TestCase
|
||||
,Services_JSON::decode('a:1',
|
||||
Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT)
|
||||
);
|
||||
$this->assertEquals(
|
||||
['a.b@c'=>1]
|
||||
,Services_JSON::decode('a.b@c:1',
|
||||
Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT)
|
||||
);
|
||||
}
|
||||
public function testsimple(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user