rails - call json api and parse one value in response -


i'm calling json api , retrieving 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 number 8174 in variable in rails, how do this?

assign json response response variable

response = { "@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" } }

parse it

parsed_response = json.parse(response.to_josn)

after parsing parsed_response hash. can access number parsed_response hash

get_number = parsed_response['day']['@value']


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -