title: Return a JSON array from a Controller in Symfony
body: <p>I am trying return a JSON response from a controller in Symfony 2. Form example, in Spring MVC I can get a JSON response with @ResponseBody annotattion. I want get a JSON response, no mtter if it is a JSON Array or a Json Object, then, manipulate it with javascript in the view.</p>
  
  <p>I try the next code:</p>
  
  <pre><code>/**
       * @Route(
       *      "/drop/getCategory/",
       *      name="getCategory"
       * )
       * @Method("GET")
       */
      public function getAllCategoryAction() {
          $categorias = $this-&gt;getDoctrine()
                             -&gt;getRepository('AppBundle:Categoria')
                             -&gt;findAll();
  
          $response = new JsonResponse();
          $response-&gt;setData($categorias);
  
          $response-&gt;headers-&gt;set('Content-Type', 'application/json');
          return $response;
      }
  </code></pre>
  
  <p>But I get <code>[{},{}]</code> as Response in the browser. I try with <code>$response = new Response(json_encode($categorias));</code> too, but I get the same result. </p>