开发者

Get individual JSON objects with Ruby

开发者 https://www.devze.com 2023-01-11 14:51 出处:网络
Forgive me if this is a really stupid question, but how do I get individual items from a JSON GET with HTTParty? For example:

Forgive me if this is a really stupid question, but how do I get individual items from a JSON GET with HTTParty? For example:

require 'rubygems'
require 'httparty'
require 'pp'

player = pp HTTParty.get('http://api.dribbble.com/players/1')

will return this:

{"name"=>"Dan Cederholm",
 "avatar_url"=>
  "http://dribbble.com/system/users/1/avatars/thumb/dancederholm-peek.jpg?1261060245",
 "twitter_screen_name"=>"simplebits",
 "shots_count"=>148,
 "location"=>"Salem, MA",
 "created_at开发者_开发知识库"=>"2009/07/07 21:51:22 -0400",
 "following_count"=>375,
 "draftees_count"=>103,
 "url"=>"http://dribbble.com/players/simplebits",
 "id"=>1,
 "followers_count"=>2119,
 "drafted_by_player_id"=>nil}

How do I get an individual item, like, say the name?


player["name"]

The returned object is a Hash


player.name seems like a most natural thing to try. And in general, you can check player.class to determine result type.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号