Reputation: 1771
As you can see, the 'cover' and 'parking' index are both arrays. But when i return the response I get something like this.
The 'cover' and 'parking' key are both not showing values in the json response. So this is my controller:
public function getPageInfoAction($page)
{
$request = (new FacebookRequest(
$this->initAppAction(),
'GET',
"/{$page}"
))->execute();
$graphObject = $request->getGraphObject();
//dump($graphObject);
//die;
return $graphObject->asArray();
}
This is my config.yml file
#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
So how can i return the correct json response?
Upvotes: 1
Views: 631
Reputation: 1771
Ok I found an answer to this. As my array also had an object as value, the serializer was returning empty json object while returning the response to json. So to solve that I checked whether the key is object or not
foreach($options as $t){
if(isset($graphObject[$t]))
//
$pageInfo[$t] = gettype($graphObject[$t])== 'object'?(array)$graphObject[$t]:$graphObject[$t];
}
Upvotes: 1