我是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 –