问题尝试将实体编码为json [英] Problems try encode entity to json
问题描述
我尝试使用以下代码:
$em = $this->getDoctrine()->getManager();
// Get the entities repository
$sesiones_registradas = $em->getRepository('AuditBundle:AuditSession')->findAll();
// Instance the object
$serializer = new Serializer(array(new JsonEncoder()),array(new GetSetMethodNormalizer()));
// Convert only an item
foreach($sesiones_registradas as $sesion){
echo $serializer->normalize($sesion,'json');
break;
}
// Stop script
die();
最后一个代码,失败:
无法规范类型的对象 AppsManantiales \ AuditBundle \ Entity \ AuditSession,不支持 找到规范化器.
如果将$serializer->normalize($sesion,'json')
更改为$serializer->serialize($sesion, 'json');
,则错误消息为:
不支持json格式的序列化
有什么想法吗?
使用JMS序列化程序包
可以在此处找到文档: http://jmsyst.com/bundles/JMSSerializerBundle >
im try encode an Doctrine entity as JSON string, to send as Ajax response. So, i check the doc: The Serializer Component
I try with this code:
$em = $this->getDoctrine()->getManager();
// Get the entities repository
$sesiones_registradas = $em->getRepository('AuditBundle:AuditSession')->findAll();
// Instance the object
$serializer = new Serializer(array(new JsonEncoder()),array(new GetSetMethodNormalizer()));
// Convert only an item
foreach($sesiones_registradas as $sesion){
echo $serializer->normalize($sesion,'json');
break;
}
// Stop script
die();
Last code, fails saying:
Could not normalize object of type AppsManantiales\AuditBundle\Entity\AuditSession, no supporting normalizer found.
And if change $serializer->normalize($sesion,'json')
by $serializer->serialize($sesion, 'json');
The error message is:
Serialization for the format json is not supported
Any ideas ?.
Use the JMS Serializer Bundle
The docs can be found here: http://jmsyst.com/bundles/JMSSerializerBundle
这篇关于问题尝试将实体编码为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!