PHP code example of php-enspired / simple-json
1. Go to this page and download the library: Download php-enspired/simple-json library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-enspired / simple-json example snippets
use AT\Simple\Json\Json;
// example data
$a = ["foo" => "one", "bar" => "two"];
// basic encoding and decoding (note $assoc = true is the default mode)
$json = Json::default();
$j = $json->encode($a); // {"foo":"one","bar":"two"}
$a === $json->decode($j); // bool (true)
// special options - e.g., "pretty" formatting
Json::pretty()->encode($a);
/*
{
"foo": "one",
"bar": "two"
}
*/
// decoding objects as stdClass
(new Json([Json::DECODE_ASOOC => false]))->decode($j);
/*
object(stdClass)#1 (2) {
["foo"]=>
string(3) "one"
["bar"]=>
string(3) "two"
}
*/