2015-09-24 115 views

回答

0
$url="https://api.themoviedb.org/3/movie/popular?api_key=52385ff92cb9105e52d86c4786293ce8&page=1"; 

使用cURL

// Initiate curl 
$ch = curl_init(); 
// Disable SSL verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch, CURLOPT_URL,$url); 
// Execute 
$result=curl_exec($ch); 
// Closing 
curl_close($ch); 

// Will dump json data 
var_dump(json_decode($result, true)); 

使用file_get_contents

$result = file_get_contents($url); 
// Will dump json data 
var_dump(json_decode($result, true)); 
0

關於使用什麼代碼如下?

$url = "https://api.themoviedb.org/3/movie/popular?api_key=52385ff92cb9105e52d86c4786293ce8&page=1"; 
$json = file_get_contents($url); 
$obj = json_decode($json); 
var_dump($obj); 
0

使用Ajax後,您可以調用URL來獲取josn數據如下。從jquery.com下載最新的jquery。

您可以使用http://jsonlint.com/網站來驗證和格式化json數據,以便您輕鬆理解json數據的結構。

$.ajax({ 
    url: 'https://api.themoviedb.org/3/movie/popular?api_key=52385ff92cb9105e52d86c4786293ce8&page=1', 
    type: 'POST', 
    success: function(resp) 
    { 
     var jsonObj=$.parseJSON(resp); //converting json string to jsonobject 
     var results=jsonObj.results; //to gest result array from json code 
     var page_number=jsonObj.page; // to get page number from json data 

    } 
})