PHP从json ticker获取价值

时间:2013-10-17 22:45:31

标签: php json

Ticker:

{"high": "145.00", "last": "143.92", "timestamp": "1382049657", "bid": "143.81", "volume": "17883.09636191", "low": "135.00", "ask": "143.92"}

我如何从这张票中“询问”价值?

我使用此代码来获取它:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.bitstamp.net/api/ticker/');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$getit= curl_exec($ch);
curl_close($ch);

echo $getit;

1 个答案:

答案 0 :(得分:2)

网站回复位于JSON,您必须先使用json_decode将其解码为数组。

$ticket = json_decode($getit, true);

echo $ticket['ask'];