Reto Bhunjun wrote in post #1177949: > Currently I am doing the Ruby on Rails Tutorial from Michael Hartl. I am > developing that code within the cloud9 IDE. What I am interested in > ultimately is to develop some application relating to cryptocurrencies > especially the counterparty protocol. For that, I want to read data from > the blockscan API (google that). There are API requests I want to made > for receiving blockchain data. This data is delivered in json. > Now as a starter, I do not know how to read this json data into a Ruby > variable, do something with it, and render it to a page. Can some one > provide me example code (only the essential lines) that would accomplish > what I wish to do? > > Sincerely
After you receive the json data from api server, you can use the JSON module to parse these data. For example: ``` require 'open-uri' require 'json' req = open('http://xcp.blockscan.com/api2?module=asset&action=list&page=1&count=10') data = JSON.load(req.read) ``` The var data that return by JSON.load function may be a Ruby Hash or Array type. If you want to render it to a page, you can use it in the view and display it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c2e5b68e8523c9ca3ef70e1c34987cb7%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.