谷歌财经JSON不能使用超过1个符号


Google Finance JSON does not work with more than 1 symbol

我正在使用谷歌财经的PHP和JSON来获取实时股票更新/报价http://finance.google.com/finance/info?client=ig&q=GOOG(这只是一个例子)我的代码与上述链接配合使用正常(因为它只有一个我想获得的股票,即 GOOG)但是如果我尝试在最后添加更多股票代码

{
    <?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("'n", "", $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 />"; 
    ?>
}
<?php 
$url="http://finance.google.com/finance/info?client=ig&q=GOOG,AAPL,MAC";
$quote= file_get_contents($url);
$json = str_replace("'n", "", $quote); //clean
$data = substr($json, 4, strlen($json) -5); 
$json_output = json_decode($data, true);  
echo '<pre>';
print_r($json_output);

你必须从谷歌的回复中删除'//'。

$quote= file_get_contents($url);
$json = str_replace('// [', ' [', $quote);
$data = substr($json, 4, strlen($json) -5); 
$results = json_decode($quote, true);
echo '<pre>';
print_r($results);