2015-08-09 41 views

回答

1

您可以使用json_decode爲(參見:http://docs.php.net/json_decode

<?php 
$json_url = "https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27https://www.facebook.com/%27&format=json"; 
$json = file_get_contents($json_url); 
$json = json_decode($json, true); 

print_r($json); 

echo "Number of likes : " . $json[0]['like_count']; 

?> 
+0

謝謝 - 那曾經有一種魅力! – Kev

0

當你正在返回的JSON字符串,以便在PHP中使用該數據將其轉換爲它的PHP等效數據類型使用json_decode() function,如下所示:_

<?php 
$json_string = file_get_contents('http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27https://www.facebook.com/%27&format=json'); 

$json = json_decode($json_string); 
echo json_last_error_msg().PHP_EOL; 

echo $json[0]->like_count;