【发布时间】:2015-10-12 14:51:02
【问题描述】:
作为我尝试并通过试用删除以从返回中获取 json 内容的代码如下 我用的方法。
$date= YYYYMMDD;
//example '20140113'
$handle = fopen('http://finance.yahoo.com/connection/currency-converter-cache?date='.$date.'', 'r');
//sample code is http://finance.yahoo.com/connection/currency-converter-cache?date=20140208 paste the url in browser;
// use loop to get all until end of content
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
代码以 yahoo 和 json 格式返回给定的批量
所以删除未知格式
"/**/YAHOO.Finance.CurrencyConverter.addConversionRates (" and ends with ");"
由
$contents = str_replace('/**/YAHOO.Finance.CurrencyConverter.addConversionRates(','',$contents);
$contents = str_replace(');','',$contents);
$obj = json_decode($contents,true);
then loop the content by
foreach($obj['list']['resources'] as $key0 => $value0){
}
【问题讨论】:
-
此端点设计为与 javascript 一起使用。您所说的“未知格式”是在命中此端点并且您正在使用他们的框架时调用的回调函数。
标签: php json parsing yahoo-api yahoo-finance