I am reading a JSON like this:
[
{
"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
}
]
Using this:
json = File.read("#{symbols[0]}.json")
Then doing this:
result = JSON.parse(json)
Then, when I want to select the first value for the key value “Low”, I did this:
puts result[0]['Low']
This returned 58.75 (correct).
But I want to get the first three values for “Low”. I tried doing the following, but it doesn’t work (says can’t convert string to integer). Why?
puts result[0..2]['Low']
1 Answer