显示密钥始终在变化的键值

时间:2017-06-20 16:08:38

标签: php json

我有一个php类,可以从json api调用中获取数据。我想从特定键中获取特定值,但键是基于日期和时间的,所以它总是在变化。我想创建一个使用Date()并匹配其格式的变量,但我希望有一种更简单的方法。

这是json

{
    "Meta Data": {
        "1. Information": "Intraday (1min) prices and volumes",
        "2. Symbol": "UGA",
        "3. Last Refreshed": "2017-06-20 11:47:00",
        "4. Interval": "1min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (1min)": {
        "2017-06-20 11:47:00": {
            "1. open": "22.7500",
            "2. high": "22.7500",
            "3. low": "22.7500",
            "4. close": "22.7500",
            "5. volume": "200"
        },
        "2017-06-20 10:38:00": {
            "1. open": "22.6000",
            "2. high": "22.6000",
            "3. low": "22.6000",
            "4. close": "22.6000",
            "5. volume": "300"
        }
}

这就是我的php看起来像

            $result = curl_exec($ch);
            $json = json_decode($result, true);

            echo $json["Time Series (1min)"]["2017-06-20 11:47:00"]["1. open"];

0 个答案:

没有答案