[英]Adressing PHP array decoded from JSON
我正在加載一個JSON數組並將其解碼為PHP數組
$jsonfile = file_get_contents('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=15min&outputsize=full&apikey=demo');
$jsonarray = json_decode($jsonfile);
var_dump($jsonarray);
到目前為止,我得到一個看起來像這樣的數組:
object(stdClass)#1 (2) {
["Meta Data"]=> object(stdClass)#2 (5) {
["1. Information"]=> string(49) "Daily Prices (open, high, low, close) and Volumes"
["2. Symbol"]=> string(5) "AAWVX"
["3. Last Refreshed"]=> string(10) "2017-06-30"
["4. Output Size"]=> string(9) "Full size"
["5. Time Zone"]=> string(10) "US/Eastern"
}
["Time Series (Daily)"]=> object(stdClass)#3 (105) {
["2017-06-30"]=> object(stdClass)#4 (5) {
["1. open"]=> string(7) "10.5100"
["2. high"]=> string(7) "10.5100"
["3. low"]=> string(7) "10.5100"
["4. close"]=> string(7) "10.5100"
["5. volume"]=> string(1) "0"
}
["2017-06-29"]=> object(stdClass)#5 (5) { ["1. open"]=> string(7) "10.4800" ["2. high"]=> string(7) "10.4800" ["3. low"]=> string(7) "10.4800" ["4. close"]=> string(7) "10.4800" ["5. volume"]=> string(1) "0" }
["2017-06-28"]=> object(stdClass)#6 (5) { ["1. open"]=> string(7) "10.5600" ["2. high"]=> string(7) "10.5600" ["3. low"]=> string(7) "10.5600" ["4. close"]=> string(7) "10.5600" ["5. volume"]=> string(1) "0" } ...
但是當我試圖像這樣對陣陣時
var_dump($jsonarray['Meta Data']);
它不起作用。
這是因為沒有參數的json_decode()
嘗試將您的json字符串轉換為stdClass對象。 如果要將其轉換為數組,則需要將第二個參數( $assoc
boolean)設置為true
:
$json = file_get_contents('LINK TO JSON OUTPUT');
$array = json_decode($json, true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.