简体   繁体   中英

Get value from php json array

Nothing seems to work to get the last price from this ticker

$uri='https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ghc';
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$json = json_decode ($execResult,true);

I've tried

$price = $json['result'][0]['Last'];
$price = $json->result[0]->Last;

and a variety of other options.. php fiddle doesn't offer a link

var_dump($json);

returns

{"success":true,"message":"","result":[{"MarketName":"BTC-GHC","High":0.00000474,"Low":0.00000429,"Volume":345725.27775903,"Last":0.00000468,"BaseVolume":1.62834409,"TimeStamp":"2015-09-04T13:28:21.513","Bid":0.00000432,"Ask":0.00000467,"OpenBuyOrders":25,"OpenSellOrders":112,"PrevDay":0.00000429,"Created":"2014-10-09T01:05:23.733"}]}

If you want curl_exec to return the data, you have to set an option:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

Also if you do not want number to be displayed in scientific notation, you can convert it using this function:

$price = number_format($price, 8);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM