【发布时间】:2016-12-04 21:31:16
【问题描述】:
序列化和反序列化单个实体对象对我来说正常工作。
这种方式可以序列化和反序列化多个对象(对象数组)吗??
$notifications = $this->getDoctrine()
->getRepository('AppBundle:Notification')
->findAll();
$encoder = new JsonEncoder();
$normalizer = new ObjectNormalizer();
$serializer = new Serializer(array($normalizer), array($encoder));
$jsonContent = $serializer->serialize($notifications, 'json');
return new Response($jsonContent);
和
$response = curl_exec($ch); // my $jsonContent from previous code
$encoder = new JsonEncoder();
$normalizer = new ObjectNormalizer();
$serializer = new Serializer(array($normalizer), array($encoder));
$notifications = $serializer->deserialize($response, Notification::class, 'json');
然后我得到了:
属性路径构造函数需要一个字符串或一个实例 “Symfony\Component\PropertyAccess\PropertyPath”。得到:“整数” 500 内部服务器错误 - UnexpectedValueException
【问题讨论】:
-
Will 听起来很愚蠢,但错误消息确实告诉了您一切……您的属性路径构造函数正在等待
PropertyPath的一个实例,它是 PropertyAccess 的子代。但是,您的构造函数得到一个 Integer 作为参数,这显然是错误的。您可以在您的问题中添加您的构造函数以及与之相关的所有内容吗?
标签: serialization symfony php-7