1. Go to this page and download the library: Download fwhat/jsonmapper 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/ */
fwhat / jsonmapper example snippets
use Fwhat\JsonMapper\JsonMapper;
class SetObject {
public bool $bool;
public int $int;
public ?string $string = null;
public array $arrayString;
public array $arrayInt;
public float $float;
/**
* @var array
*/
public array $arrayWithDoc;
public function setString (string $str) {
$this->string = "from_set_".$str;
}
}
$jsonStr = '{
"bool": true,
"int": 1,
"string": "string",
"arrayString": [
"arrayString",
"arrayString"
],
"arrayInt": [
"arrayInt",
"arrayInt"
],
"float": 1.23,
"arrayWithDoc": ["arrayWithDoc"]
}';
$mapper = new JsonMapper;
$object = new SetObject();
$mapper->map($jsonStr, $object);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.