Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php json_解码雅虎财务数据_Php_Json_Yahoo Finance - Fatal编程技术网

Php json_解码雅虎财务数据

Php json_解码雅虎财务数据,php,json,yahoo-finance,Php,Json,Yahoo Finance,我想从yahoo finance json获取数据 url是https://query1.finance.yahoo.com/v7/finance/options/USD 我使用的代码是: function get_finance_data(){ $url ='https://query1.finance.yahoo.com/v7/finance/quote?symbols=USD'; $ch = curl_init(); curl_setopt($ch, CURLO

我想从yahoo finance json获取数据 url是
https://query1.finance.yahoo.com/v7/finance/options/USD

我使用的代码是:

function get_finance_data(){

    $url ='https://query1.finance.yahoo.com/v7/finance/quote?symbols=USD';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $result=curl_exec($ch);
    curl_close($ch);
    $data = json_decode($result, true);
    return $data;
}
这是:

public function render()
{
    $financial_entity = array();
    $market_data = $this->get_finance_data();
                $item = array (
                    'symbol'          => $market_data['underlyingSymbol'],
                );
                $financial_entity[] = $item;
            

    var_dump($market_data);
    
}
var\u dump($market\u data)上我得到了内容

array(1) { 
  ["quoteResponse"]=> array(2) { 
    ["result"]=> array(1) { 
      [0] => array(59) { 
        ["language"]=> string(5) "en-US" ["region"]=> string(2) "US" ["quoteType"]=> string(3) "ETF" ["quoteSourceName"]=> string(13) "Delayed Quote" ["triggerable"]=> bool(true) ["currency"]=> string(3) "USD" ["ytdReturn"]=> float(15.65) ["trailingThreeMonthReturns"]=> float(15.89) ["trailingThreeMonthNavReturns"]=> float(15.65) ["fiftyDayAverage"]=> float(120.12118) ["fiftyDayAverageChange"]=> float(5.0788193) ["fiftyDayAverageChangePercent"]=> float(0.042280797) ["twoHundredDayAverage"]=> float(106.89956) ["twoHundredDayAverageChange"]=> float(18.300438) ["twoHundredDayAverageChangePercent"]=> float(0.17119282) ["sourceInterval"]=> int(15) ["exchangeDataDelayedBy"]=> int(0) ["tradeable"]=> bool(false) ["preMarketChange"]=> float(0) ["preMarketChangePercent"]=> float(0) ["preMarketTime"]=> int(1619428553) ["preMarketPrice"]=> float(125.2) ["regularMarketChange"]=> float(3.9300003) ["regularMarketChangePercent"]=> float(3.240703) ["regularMarketTime"]=> int(1619208000) ["regularMarketPrice"]=> float(125.2) ["regularMarketDayHigh"]=> float(126.1111) ["regularMarketDayRange"]=> string(17) "121.22 - 126.1111" ["regularMarketDayLow"]=> float(121.22) ["regularMarketVolume"]=> int(75592) ["regularMarketPreviousClose"]=> float(121.27) ["bid"]=> float(0) ["ask"]=> float(0) ["bidSize"]=> int(8) ["askSize"]=> int(8) ["fullExchangeName"]=> string(8) "NYSEArca" ["regularMarketOpen"]=> float(121.22) ["averageDailyVolume3Month"]=> int(60909) ["averageDailyVolume10Day"]=> int(51000) ["fiftyTwoWeekLowChange"]=> float(82.729996) ["fiftyTwoWeekLowChangePercent"]=> float(1.9479631) ["fiftyTwoWeekRange"]=> string(14) "42.47 - 136.25" ["fiftyTwoWeekHighChange"]=> float(-11.050003) ["fiftyTwoWeekHighChangePercent"]=> float(-0.08110094) ["fiftyTwoWeekLow"]=> float(42.47) ["fiftyTwoWeekHigh"]=> float(136.25) ["exchange"]=> string(3) "PCX" ["shortName"]=> string(30) "ProShares Ultra Semiconductors" ["longName"]=> string(30) "ProShares Ultra Semiconductors" ["messageBoardId"]=> string(14) "finmb_32431934" ["exchangeTimezoneName"]=> string(16) "America/New_York" ["exchangeTimezoneShortName"]=> string(3) "EDT" ["gmtOffSetMilliseconds"]=> int(-14400000) ["market"]=> string(9) "us_market" ["esgPopulated"]=> bool(false) ["firstTradeDateMilliseconds"]=> int(1170340200000) ["priceHint"]=> int(2) ["marketState"]=> string(3) "PRE" ["symbol"]=> string(3) "USD" 
      } 
    } 
    ["error"]=> NULL 
  } 
} 

但我试图
var\u dump($financial\u entity)我得到了符号键的空值。

示例数据中不存在您请求的数据项-
$market\u data['underyingsymbol']
。您需要使用正确的属性名称访问数据结构的正确部分:

'symbol' => $market_data['quoteResponse']['result'][0]['symbol'];

很明显,
$market\u data
不包含名为
underyingsymbol
的属性。那么您希望
$market\u data['underyingsymbol']
返回什么呢?你的问题毫无意义。您需要从实际存在的
$market\u data
中选择一些内容。当我尝试打印e.x
$market\u data['language']
时,我得到的结果是空的}},这是因为market\u数据也不包含该属性。阅读输出-它清楚地显示“语言”在数组中的一个对象中,而它本身在另一个对象中。它不在顶层。@ADyson这是一种完整的od语言,但相同的NULL
$market\u data['optionChain']['result'][0]['language']
不明白,显示
语言的值应该是什么样子?