我正在尝试使用Symfony 4.1从数据库中返回值,就在我了解Serializer
时:
public function __construct()
{
$this->serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
}
然后,我的方法来获取所有结果:
public function fetchAction()
{
$repository = $this->getDoctrine()->getRepository(Task::class);
$tasks = $this->serializer->serialize($repository->findAll(), "json");
return $this->json([
'tasks' => $tasks
]);
}
但不知何故,datetime
的一个字段附加了另一个包含许多其他垃圾信息的对象。
{
"tasks": "[{\"id\":1,\"description\":\"Lorem ipsum dolor\",\"createdAt\":{\"timezone\":{\"name\":\"Asia\\\/Shanghai\",\"transitions\":[{\"ts\":-9223372036854775808,\"time\":\"-292277022657-01-27T08:29:52+0000\",\"offset\":29143,\"isdst\":false,\"abbr\":\"LMT\"},{\"ts\":-2147483648,\"time\":\"1901-12-13T20:45:52+0000\",\"offset\":28800,\"isdst\":false,\"abbr\":\"CST\"},{\"ts\":-933494400,\"time\":\"1940-06-02T16:00:00+0000\",\"offset\":32400,\"isdst\":true,\"abbr\":\"CDT\"},{\"ts\":-923130000,\"time\":\"1940-09-30T15:00:00+0000\",\"offset\":28800,\"isdst\":false,\"abbr\":\"CST\"},{\"ts\":-908784000,\"time\":\"1941-03-15T16:00:00+0000\",\"offset\":32400,\"isdst\":true,\"abbr\":\"CDT\"},{\"ts\":-891594000,\"time\":\"1941-09-...,
如何删除所有这些不必要的数据?为什么还有呢?