Decode a json string into a class
composer require mateodioev/jsondecoder
use Mateodioev\Json;
Create a class with public atributes, egg:
class User {
public int $id;
public string $name;
public string $username;
}
$jsonRaw = '{"id": 1, "name": "Mateo", "username": "mateodioev"}';
$json = new JSON($jsonRaw);
$u = new User;
$json->decode($u)
Now var $u
containts content of $jsonRaw
var_dump($u);
example output:
class User#2 (3) {
public int $id =>
int(1)
public string $name =>
string(5) "Mateo"
public string $username =>
string(10) "mateodioev"
}
Mateodioev\Json\JsonDecodeException