0
我想將下面的json轉換爲python字典,但它轉換爲python字符串。我只對最後一天的關鍵(例如2017-11-02)和'2。符號'在下面的json來自alphavantage。我做了以下事情,正如你所看到的,它被存儲爲一個列表。我如何將它作爲字典存儲?將json轉換爲python字典
>>> import json
>>> test=ts.get_daily('AAPL')
>>>
>>> s=json.dumps(test)
>>> book=json.loads(s)
>>> book[0]['2017-11-02']['4. close']
'168.1100'
>>> type(book)
<class 'list'>
>>>
[
{
'2017-11-02': {
'1. open': '15.1800',
'2. high': '15.1800',
'3. low': '15.1800',
'4. close': '15.1800',
'5. volume': '0'
},
'2017-11-01': {
'1. open': '15.1600',
'2. high': '15.1600',
'3. low': '15.1600',
'4. close': '15.1600',
'5. volume': '0'
},
'2017-06-14': {
'1. open': '13.4700',
'2. high': '13.4700',
'3. low': '13.4700',
'4. close': '13.4700',
'5. volume': '0'
}
},
{
'1. Information': 'Daily Prices (open, high, low, close) and Volumes',
'2. Symbol': 'WFAAX',
'3. Last Refreshed': '2017-11-02',
'4. Output Size': 'Compact',
'5. Time Zone': 'US/Eastern'
}
]
請告訴我們你走到這一步, –