引用JSON Python字典中没有标签的日期字段



因为日期字段(例如2021-03-10(嵌套在";时间序列(每日(";在下面的json.dumps列表中,字段没有标签(例如"日期"(,我很难知道如何在Python代码中引用它以存储在数组中。

"Meta Data": {
"1. Information": "Daily Time Series with Splits and Dividend Events",
"2. Symbol": "TSCO.LON",
"3. Last Refreshed": "2021-03-11",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2021-03-11": {
"1. open": "222.8",
"2. high": "223.3",
"3. low": "219.6",
"4. close": "220.0",
"5. adjusted close": "220.0",
"6. volume": "18356667",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0"
},
"2021-03-10": {
"1. open": "221.7",
"2. high": "223.063",
"3. low": "219.68",
"4. close": "222.2",
"5. adjusted close": "222.2",
"6. volume": "18970902",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0"``

我通常希望使用这样的东西:

for item in data['Time Series (Daily)']:
dates.append(item['date'])

如有任何建议,不胜感激。

dates = data['Time Series (Daily)'].items()

这将导致返回时间序列中所有键值对的迭代器。

简单操作:

dates = data['Time Series (Daily)'].keys()

在评论中回答您的问题:

result = list(data['Time Series (Daily)'].items())

这是你想要的吗?

最新更新