Last active
September 16, 2016 00:55
-
-
Save mverzilli/40875d5351a83f1dfbac442b5a7eaca6 to your computer and use it in GitHub Desktop.
piedoom's problem
This file contains 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 "json" | |
class Blog | |
JSON.mapping({ | |
name: {type: String}, | |
likes: {type: Int32}, | |
following: {type: Int32}, | |
default_post_format: {type: String}, | |
}) | |
end | |
json_string = %({ | |
"response": { | |
"user": { | |
"name": "doomy", | |
"likes": 37358, | |
"following": 205, | |
"default_post_format": "html"} | |
}}) | |
pull = JSON::PullParser.new(json_string) | |
blog = pull.on_key!("response") do | |
pull.on_key!("user") do | |
Blog.new(pull) | |
end | |
end | |
pp blog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment