我正在阅读这样的 JSON:
[
{
"Low": 8.63,
"Volume": 14211900,
"Date": "2012-10-26",
"High": 8.79,
"Close": 8.65,
"Adj Close": 8.65,
"Open": 8.7
},
{
"Low": 8.65,
"Volume": 12167500,
"Date": "2012-10-25",
"High": 8.81,
"Close": 8.73,
"Adj Close": 8.73,
"Open": 8.76
},
{
"Low": 8.68,
"Volume": 20239700,
"Date": "2012-10-24",
"High": 8.92,
"Close": 8.7,
"Adj Close": 8.7,
"Open": 8.85
},
{
"Low": 8.78,
"Volume": 23433900,
"Date": "2012-10-23",
"High": 8.94,
"Close": 8.78,
"Adj Close": 8.78,
"Open": 8.93
}
]
使用这个:
json = File.read("#{symbols[0]}.json")
然后这样做:
result = JSON.parse(json)
然后,当我想为键值“Low”选择第一个值时,我这样做了:
puts result[0]['Low']
这返回 58.75(正确)。
但我想获得“低”的前三个值。我尝试执行以下操作,但它不起作用(说不能将字符串转换为整数)。为什么?
puts result[0..2]['Low']