duankuaiwang2706 2015-03-09 22:03
浏览 35

Google财经JSON不支持超过1个符号

I'm using PHP and JSON from Google finance to get real-time stock updates/quotes using http://finance.google.com/finance/info?client=ig&q=GOOG (this is just an example) My code works fine with above mentioned link (because it only has one stock that I want to get i.e GOOG) but if I try to add few more stock symbols at the end

{
    <?php                                                   
        <?php $url="http://finance.google.com/finance/info?client=ig&q=GOOG,AAPL,MAC "
         /* (here I'm trying to get data for 3 stocks (i.e GOOG, AAPL, MAC) 
         it generates the JSON but I'm unable to change it into proper Array.*/          
              $g_f_data= file_get_contents($url);
              $json = str_replace("
", "", $g_f_data);
              $data = substr($json, 4, strlen($json) -5);

              $json_output = json_decode($data, true);
              echo"<pre>";
              print_r ($json_output);
              echo"</pre>";
             echo $json_output['t'],$json_output['l'],$json_output['cp'];echo "<br />"; 
    ?>
}
  • 写回答

2条回答 默认 最新

  • douboshan1466 2015-03-09 22:32
    关注
    <?php 
    
    $url="http://finance.google.com/finance/info?client=ig&q=GOOG,AAPL,MAC";
    
    $quote= file_get_contents($url);
    
    $json = str_replace("
    ", "", $quote); //clean
    $data = substr($json, 4, strlen($json) -5); 
    $json_output = json_decode($data, true);  
    echo '<pre>';
    print_r($json_output);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度