使用symfony中的jsonResponse格式化json无效

时间:2017-05-16 08:31:56

标签: json symfony

我在我的symfony项目中使用Json数据,在我的控制器中我使用New Response返回数据,它就像是:

{"cn":"dvsdvsdvergfe","gender":"M","fgff":"data","mail":"sino@hotmail.fr","sn":"SINO","uid":"sino"}

但如果我在JsonResponse中返回我的数据,我会有这样的数据格式:

" {\"cn\":\"dvsdvsdvergfe\",\"gender\":\"M\",\"fgff\":\"data\",\"mail\":\"sino@hotmail.fr\",\"sn\":\"SINO\",\"uid\":\"sino\", }"

控制器:

public function getUserByUidAction($uid)
    {
        $url = self::Ws_URL . self::Ws_PORT . self::Ws_GetUserByUID . $uid;
        $headers = array() ;
        $headers[] = "auth_token: ".self::Ws_Token ;
        $headers[] = "Content-Type: application/json" ;
        $arrContextOptions=array(
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ),
            "http" =>array(
                "method" => "GET",
                "header" => "auth_token: ".self::Ws_Token
            )
        );

        $response   = file_get_contents($url, true, stream_context_create($arrContextOptions));

       $viewHandler = $this->get('fos_rest.view_handler');
       $view = View::create($response);
       $view->setFormat('json');
       return $viewHandler->handle($view);

        return New Response($response) ;

    }

发生了什么事?

0 个答案:

没有答案