Я пытаюсь перебрать JSON из моего вызова API и отобразить каждую высокую цену сделки в моем приложении реакции (конечной целью будет создание графика). Проблема в том, что мне нужно знать точную строку метки времени заранее, потому что API не структурирован численно.
Вот мой код (см. Журнал консоли). В настоящее время я проверяю правильную конечную точку ПЕРЕД созданием цикла, поэтому вы его не видите.
Если вам интересно, this.state.stock - это AMD, который я использую для тестирования. В конце концов это будет пользовательский ввод.
Как я должен пройти через?
componentDidMount() {
axios
.get(`https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=${this.state.stock}&interval=5min&apikey=J6ED0QFWG3T1KLTD`)
.then((response) => {
this.setState({
dailyQuote: response.data
})
console.log("daily quote",this.state.dailyQuote['Time Series (5min)']['2019-06-27 14:15:00']['2. high'])
})
}
Вот пример данных вызова API
{
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "amd",
"3. Last Refreshed": "2019-06-28 16:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (5min)": {
"2019-06-28 16:00:00": {
"1. open": "30.3900",
"2. high": "30.4000",
"3. low": "30.3300",
"4. close": "30.3700",
"5. volume": "2242133"
},
"2019-06-28 15:55:00": {
"1. open": "30.3700",
"2. high": "30.4400",
"3. low": "30.3601",
"4. close": "30.3900",
"5. volume": "1294256"
},
"2019-06-28 15:50:00": {
"1. open": "30.4350",
"2. high": "30.4500",
"3. low": "30.3500",
"4. close": "30.3700",
"5. volume": "1265203"
},
"2019-06-28 15:45:00": {
"1. open": "30.4750",
"2. high": "30.4750",
"3. low": "30.4300",
"4. close": "30.4350",
"5. volume": "664693"
},
"2019-06-28 15:40:00": {
"1. open": "30.4850",
"2. high": "30.4900",
"3. low": "30.4550",
"4. close": "30.4700",
"5. volume": "539474"
},
"2019-06-28 15:35:00": {
"1. open": "30.4750",
"2. high": "30.5050",
"3. low": "30.4500",
"4. close": "30.4900",
"5. volume": "685410"
},
"2019-06-28 15:30:00": {
"1. open": "30.5100",
"2. high": "30.5200",
"3. low": "30.4600",
"4. close": "30.4800",
"5. volume": "376771"
},
"2019-06-28 15:25:00": {
"1. open": "30.5400",
"2. high": "30.5600",
"3. low": "30.5000",
"4. close": "30.5101",
"5. volume": "288554"
},
"2019-06-28 15:20:00": {
"1. open": "30.5600",
"2. high": "30.5600",
"3. low": "30.5200",
"4. close": "30.5350",
"5. volume": "218143"
},
"2019-06-28 15:15:00": {
"1. open": "30.5703",
"2. high": "30.5800",
"3. low": "30.5400",
"4. close": "30.5557",
"5. volume": "281558"
},
"2019-06-28 15:10:00": {
"1. open": "30.5700",
"2. high": "30.5850",
"3. low": "30.5500",
"4. close": "30.5750",
"5. volume": "290714"
},
"2019-06-28 15:05:00": {
"1. open": "30.5803",
"2. high": "30.6100",
"3. low": "30.5750",
"4. close": "30.5750",
"5. volume": "169868"
},
"2019-06-28 15:00:00": {
"1. open": "30.6050",
"2. high": "30.6100",
"3. low": "30.5800",
"4. close": "30.5850",
"5. volume": "186744"
},
"2019-06-28 14:55:00": {
"1. open": "30.5650",
"2. high": "30.6100",
"3. low": "30.5500",
"4. close": "30.6050",
"5. volume": "378489"
},
"2019-06-28 14:50:00": {
"1. open": "30.5700",
"2. high": "30.5800",
"3. low": "30.5500",
"4. close": "30.5650",
"5. volume": "247525"
},
}