Created
February 23, 2017 17:10
-
-
Save dmmfll/126b4ec98557bc0bd267641b6edbed96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gist_url | |
auto_gistup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require the builtin gem | |
require 'json' | |
# create some fake data: an array of hashes | |
data = 10.times.each_with_index.map do |i| | |
{20.times.map do | |
("a".."z").to_a.sample | |
end.join => i} | |
end | |
# turn data into json string which is the same thing a lot of API's will return | |
# in an HTTP response body | |
json_data = data.to_json | |
p json_data.class | |
# undo the process | |
# this is what you do with the JSON string returned in | |
# the body of an HTTP response | |
converted_data = JSON.parse(json_data) | |
p converted_data | |
p converted_data.class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment