maxv Posted September 19, 2022 Share Posted September 19, 2022 My purpose is to get quote price of quote symbol 'crge' I try json_decode to data from yahoo finance api: I need the value of "regularMarketPrice" (in this case it should return "1.965") Actual result I get is empty... $url=' $https://query1.finance.yahoo.com/v11/finance/quoteSummary/crge?modules=Price'; $data=url_get_contents($url); $arr=json_decode($data,true); $price=$arr["regularMarketPrice"]; echo $price; url_get_contents return this json string: {"quoteSummary":{"result":[{"price":{"maxAge":1,"preMarketChangePercent":{"raw":0.0856624,"fmt":"8.57%"},"preMarketChange":{"raw":0.1649,"fmt":"0.16"},"preMarketTime":1663594102,"preMarketPrice":{"raw":2.0899,"fmt":"2.0899"},"preMarketSource":"FREE_REALTIME","postMarketChange":{},"postMarketPrice":{},"regularMarketChangePercent":{"raw":0.020779263,"fmt":"2.08%"},"regularMarketChange":{"raw":0.04000008,"fmt":"0.0400"},"regularMarketTime":1663600903,"priceHint":{"raw":4,"fmt":"4","longFmt":"4"},"regularMarketPrice":{"raw":1.965,"fmt":"1.9650"},"regularMarketDayHigh":{"raw":2.06,"fmt":"2.0600"},"regularMarketDayLow":{"raw":1.96,"fmt":"1.9600"},"regularMarketVolume":{"raw":234185,"fmt":"234.19k","longFmt":"234,185.00"},"averageDailyVolume10Day":{},"averageDailyVolume3Month":{},"regularMarketPreviousClose":{"raw":1.925,"fmt":"1.9250"},"regularMarketSource":"FREE_REALTIME","regularMarketOpen":{"raw":2.06,"fmt":"2.0600"},"strikePrice":{},"openInterest":{},"exchange":"NGM","exchangeName":"NasdaqGM","exchangeDataDelayedBy":0,"marketState":"REGULAR","quoteType":"EQUITY","symbol":"CRGE","underlyingSymbol":null,"shortName":"Charge Enterprises, Inc.","longName":"Charge Enterprises, Inc.","currency":"USD","quoteSourceName":"Nasdaq Real Time Price","currencySymbol":"$","fromCurrency":null,"toCurrency":null,"lastMarket":null,"volume24Hr":{},"volumeAllCurrencies":{},"circulatingSupply":{},"marketCap":{"raw":405100480,"fmt":"405.10M","longFmt":"405,100,480.00"}}}],"error":null}} Quote Link to comment https://forums.phpfreaks.com/topic/315346-cant-get-json-value/ Share on other sites More sharing options...
Barand Posted September 19, 2022 Share Posted September 19, 2022 decode and use print_r(). Then follow the keys. echo $data->quoteSummary->result[0]->price->regularMarketPrice->raw; Quote Link to comment https://forums.phpfreaks.com/topic/315346-cant-get-json-value/#findComment-1600770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.