Answer the question
In order to leave comments, you need to log in
How to collect an object from JSON in PHP?
Hello.
There is json, for example: It is {"name":"Jack.M","birthDate":"12.12.1991"}
necessary to collect an object of the JsonPerson class from it.
So far, only a simple constructor and implementation in it are on my mind.
class JsonPerson
{
public $name;
public $birthDate;
public function __construct($json)
{
// realization
}
}
Answer the question
In order to leave comments, you need to log in
json_encode to do from the object initially, then the structure and class should be preserved.
Well, either in the class createFromJson method to do, in it json_decode and filling the object with data.
There seems to be no magical third option.
You need jms/serializer. symfony.com/doc/current/components/serializer.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question