开发者

Symfony action with json response

I am using PHP + CURL to fetch data from a server in one of my actions. I then return the data as json from my action.

My action looks like this

public function executeTest(sfWebRequest $request)
{
    $json = $this->getServerResponse();  // fetches data using CURL
    $this->getResponse()->setContentType('text/json');
    return $this->renderText($json);
}

When the above action is executed, the received json strng is (for example):

{ 'ok': true }1

If I change the last line in the action above to return $this->renderText('foo');

the returned JSON is:

{ 'ok': true }foo

If I change the last line in the action above to return $this->renderText('');

the returned JSON is:

{ 'ok': true }

My question are:

  1. Why is the JSON data from the server being displayed together with the text in my renderText() method?

  2. Where is the '1' appended to the JSON data coming from?

  3. How do I resolve/fix this iss开发者_StackOverflow社区ue ?

I am running Symfony 1.4.x on Ubuntu


From the looks of it, your problem lies in getServerResponse(). Can't help more without seeing that function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜