2015-04-18 64 views

回答

1

只需通過file_get_contents訪問url內容。你的網頁實際上是返回一個JSON字符串,來獲取這些值轉換爲有意義的數據,它直通json_decode解碼,該訪問後相應所需要的數據:

$url = 'http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132'; 
$data = json_decode(file_get_contents($url), true); 
$sellorderprice = $data['return']['DOGE']['sellorders'][0]['price']; 
echo $sellorderprice; 

該代碼實際上直接指向指數爲零0其獲得的第一個價格。如果您需要獲得所有項目的只是簡單地迴應他們都需要迭代的所有項目通foreach

foreach($data['return']['DOGE']['sellorders'] as $sellorders) { 
    echo $sellorders['price'], '<br/>'; 
} 
+0

這表示感謝。 – Ben

+0

肯定@Ben很高興這有幫助 – Ghost

1

它的簡單,你只需要像這樣的解碼JSON:

 
    $json = file_get_contents("http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132"); 
    $arr = json_decode($json, true); 
    $sellorderprice = $arr['return']['DOGE']['sellorders'][0]['price'];