我使用curl从facebook图表中获取Feed:
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
// CURLOPT_AUTOREFERER => true,
// CURLOPT_CONNECTTIMEOUT => 120,
// CURLOPT_TIMEOUT => 120,
// CURLOPT_MAXREDIRS => 10,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0'
);
curl_setopt_array( $ch, $options );
$resultat = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// return
$answer = array(
'response' => 'ok',
'resultat' => $resultat
);
with cakePHP(我添加了$this->RequestHandler->respondAs('json');
)。
但是回归中存在问题:
线条没有正确显示,我的json阅读器无法读取,所以有什么好的选择来纠正它?我尝试了json_encode / decode,但并不是更好。
答案 0 :(得分:1)
尝试解码你的json并重新编码。
$answer = '{ "key": "Your json values" }';
$answer = json_encode(json_decode($answer));