PHP code example of dotink / json

1. Go to this page and download the library: Download dotink/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/ */

    

dotink / json example snippets


$json = Json\Serialize($data);

namespace Json\Normalizer;

class DateTime extends \Json\Normalizer
{
	public function jsonSerialize()
	{
		return $this->format('c');
	}
}

Json\Serialize(new DateTime('today'))

"2019-11-25T00:00:00-08:00"

json_encode(new DateTime('today'))

"{"date":"2019-11-25 00:00:00.000000","timezone_type":3,"timezone":"America\/Los_Angeles"}"

namespace Json\Normalizer\My\Library;

class Acme extends \Json\Normalizer
{
	public function jsonSerialize()
	{
		//
		// return normalized object
		//
	}
}

Json\Normalizer::setNamespace('My\Json\Normalizer')

Json\Normalizer::setContainer($container);

namespace Json\Normalizer\My\Library;

class Acme extends \Json\Normalizer
{
	public function jsonSerialize()
	{
		if ($this('nested')) {

			//
			// Return nested object's normalization
			//

		} else {

			//
			// Return non-nested object's normalization
			//

		}
	}
}

class Acme implements Json\Serializable
{
	use Json\Serialize;
}

class Acme implements Json\Serializable
{
	use Json\SerializeAllProperties;
}

class Acme implements Json\Serializable
{
	use Json\SerializeStandardProperties;
}

namespace Json\Normalizer;

class _String extends \Json\Normalizer
{
	public function jsonSerialize()
	{
		return "I'm a teapot";
	}
}

namespace My;

class DateTime extends \DateTime implements Json\Serializable
{
	use Json\Serialize;
}