Reputation: 1147
I'm calling a json api and retrieving this as the result every single time:
{
"@endDate": "2016-11-05",
"@metric": "Sessions",
"@startDate": "2016-11-05",
"@generatedDate": "11\/5\/16 6:14 PM",
"@version": "1.0",
"day": {
"@date": "2016-11-05",
"@value": "8174"
}
}
I want to get the number 8174 in a variable in rails, how do I do this?
Upvotes: 1
Views: 258
Reputation: 651
response
variableresponse = {
"@endDate": "2016-11-05",
"@metric": "Sessions",
"@startDate": "2016-11-05",
"@generatedDate": "11\/5\/16 6:14 PM",
"@version": "1.0",
"day": {
"@date": "2016-11-05",
"@value": "8174"
}
}
parsed_response = JSON.parse(response.to_josn)
parsed_response
is now a hash. So you can access the number
from parsed_response
hashget_number = parsed_response['day']['@value']
Upvotes: 1