mirror of
https://github.com/EFTEC/Services_JSON.git
synced 2026-08-20 06:25:09 +00:00
36 lines
1003 B
PHP
36 lines
1003 B
PHP
<?php /** @noinspection ForgottenDebugOutputInspection */
|
|
|
|
use eftec\ServicesJson\Services_JSON;
|
|
|
|
include '../vendor/autoload.php';
|
|
|
|
// $json_decoder = new Services_JSON(SERVICES_JSON_IN_ARR | SERVICES_JSON_LOOSE_TYPE)
|
|
|
|
|
|
$json='{hello:{a:2,b:3},world:[1,2,3,"aaa","bbbb"]}';
|
|
|
|
echo "<h1>Original:</h1><pre>$json</pre><br>";
|
|
|
|
echo "<h1>Decode as stdclass:</h1>";
|
|
echo "<pre>";
|
|
var_dump(Services_JSON::decode($json));
|
|
echo "</pre>";
|
|
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>";
|
|
|