如何将 json 值记录到控制台?
How to log json value to console?
我有下面的 json 数据。我如何 select 2020-11-06 19:50:00
的 open
值并使用 console.log() 将其记录到控制台?
{
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-11-06 20:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (5min)": {
"2020-11-06 20:00:00": {
"1. open": "114.4400",
"2. high": "114.4400",
"3. low": "114.4400",
"4. close": "114.4400",
"5. volume": "457"
},
"2020-11-06 19:50:00": {
"1. open": "114.4000",
"2. high": "114.4000",
"3. low": "114.3300",
"4. close": "114.3300",
"5. volume": "648"
}
}
}
您首先需要将其分配给一个变量,然后您应该能够像下面那样访问
var jsonData = {
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-11-06 20:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (5min)": {
"2020-11-06 20:00:00": {
"1. open": "114.4400",
"2. high": "114.4400",
"3. low": "114.4400",
"4. close": "114.4400",
"5. volume": "457"
},
"2020-11-06 19:50:00": {
"1. open": "114.4000",
"2. high": "114.4000",
"3. low": "114.3300",
"4. close": "114.3300",
"5. volume": "648"
}
}
};
console.log(jsonData["Time Series (5min)"]["2020-11-06 20:00:00"]["1. open"]);
要遍历这些值,请参阅此问题:Retrieving a property of a JSON object by index?
我有下面的 json 数据。我如何 select 2020-11-06 19:50:00
的 open
值并使用 console.log() 将其记录到控制台?
{
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-11-06 20:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (5min)": {
"2020-11-06 20:00:00": {
"1. open": "114.4400",
"2. high": "114.4400",
"3. low": "114.4400",
"4. close": "114.4400",
"5. volume": "457"
},
"2020-11-06 19:50:00": {
"1. open": "114.4000",
"2. high": "114.4000",
"3. low": "114.3300",
"4. close": "114.3300",
"5. volume": "648"
}
}
}
您首先需要将其分配给一个变量,然后您应该能够像下面那样访问
var jsonData = {
"Meta Data": {
"1. Information": "Intraday (5min) open, high, low, close prices and volume",
"2. Symbol": "IBM",
"3. Last Refreshed": "2020-11-06 20:00:00",
"4. Interval": "5min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (5min)": {
"2020-11-06 20:00:00": {
"1. open": "114.4400",
"2. high": "114.4400",
"3. low": "114.4400",
"4. close": "114.4400",
"5. volume": "457"
},
"2020-11-06 19:50:00": {
"1. open": "114.4000",
"2. high": "114.4000",
"3. low": "114.3300",
"4. close": "114.3300",
"5. volume": "648"
}
}
};
console.log(jsonData["Time Series (5min)"]["2020-11-06 20:00:00"]["1. open"]);
要遍历这些值,请参阅此问题:Retrieving a property of a JSON object by index?