Hi all,
I’ve tried to read values from a json file without success.
The following code works well:
require ‘json’
require ‘pp’
brut = File.read(‘repsol.json’)
dades = JSON.parse(brut)
p dades[‘list’][“resources”] ----> returns data but too general
p dades[‘list’][‘resources’][‘resource’] —> fails
p dades[‘list’][‘resources’][‘price’] —> fails
Pls, can anyone help me with ruby hash syntyax to address for example
the ‘price’ value?
(file content provided below)
Any help or tip will be apreciated
Thanks in advance!
Jordi
By the way, the repsol.json file follows:
{
“list” : {
“meta” : {
“type” : “resource-list”,
“start” : 0,
“count” : 2
},
“resources” : [
{
“resource” : {
“classname” : “Quote”,
“fields” : {
“name” : "ENDESA ",
“price” : “17.594999”,
“symbol” : “ELE.MC”,
“ts” : “1461080280”,
“type” : “equity”,
“utctime” : “2016-04-19T15:38:00+0000”,
“volume” : “1123718”
}
}
}
,
{
“resource” : {
“classname” : “Quote”,
“fields” : {
“name” : “REPSOL”,
“price” : “10.915000”,
“symbol” : “REP.MC”,
“ts” : “1461080280”,
“type” : “equity”,
“utctime” : “2016-04-19T15:38:00+0000”,
“volume” : “10877532”
}
}
}
]
}
}