2015-08-09 98 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;