我想从Alpha Vantage API中提取特定值,并希望在Sparkline图表中显示。
我有一个像 -
这样的JSON文件 {
"Meta Data": {
"1. Information": "Intraday Prices and Volumes for Digital Currency",
"2. Digital Currency Code": "BTC",
"3. Digital Currency Name": "Bitcoin",
"4. Market Code": "EUR",
"5. Market Name": "Euro",
"6. Interval": "5min",
"7. Last Refreshed": "2018-05-05 09:30:00",
"8. Time Zone": "UTC"
},
"Time Series (Digital Currency Intraday)": {
"2018-05-05 09:30:00": {
"1a. price (EUR)": "8213.91934125",
"1b. price (USD)": "9833.29603162",
"2. volume": "14118.15104183",
"3. market cap (USD)": "138827958.61346000"
},
"2018-05-05 09:25:00": {
"1a. price (EUR)": "8205.43730260",
"1b. price (USD)": "9823.14175648",
"2. volume": "14138.79003689",
"3. market cap (USD)": "138887338.79747999"
}
.
.
.
}
}
我想只提取"1b. price (USD)": "9833.29603162"
这个值,并将它们放在JS数组
var myvalues = [9833.296,9823.141,...];
我正在用来做其他一些任务。请帮忙!
答案 0 :(得分:0)
如果要使用JSON提取特定数据,可以使用以下代码。对于每个库,您需要更改功能。库的名称以及您需要使用的功能名称在alpah vantage文档中。
https://www.alphavantage.co/documentation/#
### FUNADMENTAL DATA > COMPANY OVERVIEW ###
# https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo
base_url = 'https://www.alphavantage.co/query?'
params = {'function': 'OVERVIEW',
'symbol': stock_ticker,
'apikey': keys}
response_data_overview = requests.get(base_url, params=params)
data_overview_Name = response_data_overview.json()['Name']
data_overview_AssetType = response_data_overview.json()['AssetType']
data_overview_Description = response_data_overview.json()['Description']
data_overview_Exchange = response_data_overview.json()['Exchange']
data_overview_Currency = response_data_overview.json()['Currency']
data_overview_Country = response_data_overview.json()['Country']
data_overview_Sector = response_data_overview.json()['Sector']
data_overview_Industry = response_data_overview.json()['Industry']
data_overview_Address = response_data_overview.json()['Address']