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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试从以下位置读取JSON格式的价格: https://poloniex.com/public?command=returnTicker

我需要的是两件事:符号 名称(如BTC_BBR,BTC_BCN等)和“highestBid”价格。 要读取梯形图,我使用以下内容:

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

但我需要 使用符号名称来读取它。 符号消失并且不时添加,因此我需要更自动地执行此操作。 如何将符号名称读入数组,结果如下:

  symbol_name [0] =“BTC_BBR”; 
symbol_name [1] =“BTC_BCN”; 
    
 
 

等等。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题