/ Published in: Ruby

An example method for fetching remote JSON data in Ruby.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'rubygems' require 'json' require 'net/http' def fetch(url) resp = Net::HTTP.get_response(URI.parse(url)) data = resp.body JSON.parse(data) end puts fetch "http://example.org/sample.json"
Comments
