当我在seralize数组时,我有类似的东西:
{"0":{"id":1,"name":"Kowalscy","familyMembers":[{"id":1,"familyMemberType":1,"user":{},"name":"Pawel","isAdmin":true,"notes":[],"email":""},{"id":2,"familyMemberType":2,"user":{},"name":"Mama Koper","isAdmin":false,"notes":[],"email":""}],"children":[]},
"1":{"id":2,"name":"Spiochy","familyMembers":[{"id":3,"familyMemberType":2,"user":{},"name":"Test Nowak","isAdmin":false,"notes":[],"email":""}],"children":[]}, .....
但我对使用JSON的数组进行deseralization有问题,我认为它看起来应该是这样的:
[{object}, {object}]
有办法改变吗?
这是我的symfony2
代码$result = $serializer->serialize($families, 'json',SerializationContext::create()->setGroups(array('getFamilies')));
编辑: 我发现“getArrayResult()”返回数组,但它不包含我的关系实体
答案 0 :(得分:1)
从内存来看,在json中将数组作为顶级是一种不好的做法。
What are "top level JSON arrays" and why are they a security risk?
另外,如果使用数组,则会丢失对象的ID。所以你失去了关系是正常的。