Prashant Sahni Blog

Parsing JSON Response in Ruby

We have to use Net::HTTP class, for that we have to require net/http ( it is inbuilt with ruby). A very use full link on Net::HTTP here

1
2
3
4
5
6
7
    require 'net/http'
    require 'rubygems'
    require 'json'

    @response = Net::HTTP.get(URI.parse("http://www.reddit.com/.json"))
    @result = JSON.parse(@response)

Now the parsed info lies in the @result, by using methods of ruby, you can parse this @result according to you your need.

comments powered byDisqus