相关疑难解决方法(0)

在Ruby中自动将JSON对象映射到实例变量

我希望能够自动将JSON对象解析为实例变量.例如,使用此JSON.

require 'httparty'

json = HTTParty.get('http://api.dribbble.com/players/simplebits') #=> {"shots_count":150,"twitter_screen_name":"simplebits","avatar_url":"http://dribbble.com/system/users/1/avatars/thumb/dancederholm-peek.jpg?1261060245","name":"Dan Cederholm","created_at":"2009/07/07 21:51:22 -0400","location":"Salem, MA","following_count":391,"url":"http://dribbble.com/players/simplebits","draftees_count":104,"id":1,"drafted_by_player_id":null,"followers_count":2214}
Run Code Online (Sandbox Code Playgroud)

我希望能够这样做:

json.shots_count
Run Code Online (Sandbox Code Playgroud)

并输出:

150
Run Code Online (Sandbox Code Playgroud)

我怎么可能这样做?

ruby parsing json

3
推荐指数
1
解决办法
2792
查看次数

标签 统计

json ×1

parsing ×1

ruby ×1