ruby on rails - Parsing JSON in Controller w/ HTTParty -
in controller have following code...
response = httparty.get('https://graph.facebook.com/zuck') logger.debug(response.body.id)
i getting nomethoderror / undefined method `id'
if do...
logger.debug(response.body)
it outputs should...
{"id":"4","name":"mark zuckerberg","first_name":"mark","last_name":"zuckerberg","link":"http:\/\/www.facebook.com\/zuck","username":"zuck","gender":"male","locale":"en_us"}
one think it's response.body.id, that's not working. in advance!
try this:
body = json.parse(response.body) id = body["id"]
for kind of thing, i'd recommend either a) using koala or b) create class using httparty. can set format: json
auto parse returned json. see here , here
Comments
Post a Comment