S
S
Steve2022-01-13 18:24:48
symfony
Steve, 2022-01-13 18:24:48

How to deserialize an array?

How to deserialize an array:

[
    {"name":"name1"},
    {"name":"name2"}
]


Returns a Student object with empty values
$student = $this->serializer->deserialize(
            $response->getContent(),
            Student::class,
            'json'
        );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2022-01-13
@CenterJoin

https://symfony.com/doc/current/components/serial...

$student = $this->serializer->deserialize(
    $response->getContent(),
    Student::class.'[]',
    'json'
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question