dpafea04148 2017-02-15 11:34
浏览 113
已采纳

PHP:json_decode - 读取类别名称

I am trying to read JSON formatted prices from: https://poloniex.com/public?command=returnTicker

what I need are two things: symbol names (like BTC_BBR, BTC_BCN, etc) and "highestBid" price for them. To read the ladder I use something like this:

$polo_price = file_get_contents('https://poloniex.com/public?command=returnTicker');
$polo = json_decode($polo_price, true);
$symbol[1] =  $polo['BTC_BBR']['highestBid'];

But i need to use symbol name to read it. The symbols disapear and are being added from time to time, so I need to do this more automatically. How can I read symbol names into an array, so the result are:

symbol_name[0] = "BTC_BBR";
symbol_name[1] = "BTC_BCN";

and so on.

  • 写回答

2条回答 默认 最新

  • dououde4065 2017-02-15 11:53
    关注

    Try this:

    <?php
    $polo_price = file_get_contents('https://poloniex.com/public?command=returnTicker');
    $polo = json_decode($polo_price, true);
    
    foreach ($polo as $symbol=>$array){
        $symbols[]=$symbol;
        $highestBids[] = $array['highestBid'];
    }
    
    print_r($symbols);
    
    print_r($highestBids);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 需求DC-DC降压电路
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 xshell无法连接提示ssh服务器拒绝密码