2015-05-23 43 views
1

enter image description hereFOS休息包沒有返回正確的json

正如你所看到的,'cover'和'parking'索引都是數組。但是當我回復我的迴應時,我得到了這樣的東西。 enter image description here

'cover'和'parking'鍵在json響應中都沒有顯示值。 所以這是我的控制器:

public function getPageInfoAction($page) 
     { 

      $request = (new FacebookRequest(
       $this->initAppAction(), 
       'GET', 
       "/{$page}" 
      ))->execute(); 

      $graphObject = $request->getGraphObject(); 
      //dump($graphObject); 
      //die; 
      return $graphObject->asArray(); 
} 

這是我config.yml文件

#fos_rest 
fos_rest: 
    param_fetcher_listener: force 
    view: 
     view_response_listener: 'force' 
     formats: 
      xml: true 
      json: true 
     templating_formats: 
      html: true 
    format_listener: 
     rules: 
      - { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true } 
    exception: 
     codes: 
      'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404 
      'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT 
     messages: 
      'Symfony\Component\Routing\Exception\ResourceNotFoundException': true 
    allowed_methods_listener: true 
    access_denied_listener: 
     json: true 
    body_listener: true 
    disable_csrf_role: ROLE_API 

所以,我怎麼能返回正確的JSON響應?

+0

請轉換您的截圖到純文本 –

+0

後精確的輸出,而不是屏幕截圖 – Rahul

回答

1

好的,我找到了一個答案。 由於我的數組也有一個對象作爲值,序列化程序返回空json對象,同時將響應返回給json。因此,要解決我檢查開關是否物體或不

foreach($options as $t){ 
     if(isset($graphObject[$t])) 
      // 
      $pageInfo[$t] = gettype($graphObject[$t])== 'object'?(array)$graphObject[$t]:$graphObject[$t]; 
    }