$json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2';
$jsondata = file_get_contents($json_string);
我是新的php。也許它的愚蠢問題。但是,獲得所有市場最新價格的最簡單方法是什麼?在JSON字符串中獲取嵌套數組的最簡單方法
$json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2';
$jsondata = file_get_contents($json_string);
我是新的php。也許它的愚蠢問題。但是,獲得所有市場最新價格的最簡單方法是什麼?在JSON字符串中獲取嵌套數組的最簡單方法
使用json_decode
函數將json字符串轉換爲數組&相應地遍歷數組。
$jsondata = file_get_contents($json_string);
$array = json_decode($jsondata,true);
foreach($array['return']['markets'] as $lprice) {
$latest_price[$lprice['label']] = $lprice['lasttradeprice'];
}
echo "<pre>";
print_r($latest_price);
echo "<pre>";
你知道如何使用方法 方法:getmarkets 輸入:N/A 輸出:在活躍市場上的陣列 標籤 - \t名稱對於這個市場 primary_currency_code - \t主要貨幣代碼 這個例如 – user1761818
@ user1761818我沒有真正在問你。 –
嘗試
$decoded = json_decode($jsondata);
$latestprices = array();
foreach($decoded['return']['markets'] as $val) {
$latestprices[$val['label']] = $val['lasttradeprice'];
}
你的JSON的樣子,如果你發佈這將是有益的,看看和建議。 –
JSON可以在URL中可以看到,但它是一個相當大的一個 – asiviero