我是PHP的初学者& Symfony 3和我有一个问题: json_encode返回空对象。您可以查看下面的图片和代码。空JSON返回 - Symfony3
/**
* @Rest\Get("/user")
*/
public function getAction()
{
$restresult = $this->getDoctrine()->getRepository('AppBundle:User')->findAll();
if ($restresult === null) {
return new View("there are no users exist", Response::HTTP_NOT_FOUND);
}
return new Response(json_encode($restresult), Response::HTTP_OK);
}
你可以使用'JsonResponse'顺便说一句,看看这里:https://symfony.com/doc/current/components/http_foundation.html#creating-a-json-response –