Files
Services_JSON/examples/example_decode_unquoted.php
T
jorgecc 4f2892bc19 2.5
2025-03-02 18:59:24 -03:00

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>";