donglefu6195 2015-09-04 16:44
浏览 43

从php json数组中获取价值

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"}]}
  • 写回答

1条回答 默认 最新

  • dongqiya9552 2015-09-04 17:09
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退