0

更新:我试过

json = JSON.parse(@twitch.getStreams(game:"League of Legends").to_json)['body']['streams']
json.first("_link")

但是现在我没有将 String 隐式转换为 Integer

我有一个 JSON,我需要从 JSON 中找到某些参数。这是我收到的这个请求:

@twitch.getStreams(game:"League of Legends")[:body][:streams}

我得到一个巨大的 JSON,如下所示,它响应每个 ID。我真的只关心“观众”、“预览”和“_links”,我怎样才能只过滤那些?

{"_id"=>7699557472, "game"=>"League of Legends", "viewers"=>14403, "preview"=>{"small"=>"http://static-cdn.jtvnw.net/previews-ttv/live_user_flosd-80x50.jpg", "medium"=>"http://static-cdn.jtvnw.net/previews-ttv/live_user_flosd-320x200.jpg", "large"=>"http://static-cdn.jtvnw.net/previews-ttv/live_user_flosd-640x400.jpg", "template"=>"http://static-cdn.jtvnw.net/previews-ttv/live_user_flosd-{width}x{height}.jpg"}, "_links"=>{"self"=>"https://api.twitch.tv/kraken/streams/flosd"}, "channel"=>{"mature"=>nil, "abuse_reported"=>nil, "status"=>"Boxbox", "display_name"=>"flosd", "game"=>"League of Legends", "delay"=>0, "_id"=>38881685, "name"=>"flosd", "created_at"=>"2012-12-30T06:58:18Z", "updated_at"=>"2013-12-01T18:20:51Z", "logo"=>"http://static-cdn.jtvnw.net/jtv_user_pictures/flosd-profile_image-d3615fd1a2dc6187-300x300.png", "banner"=>"http://static-cdn.jtvnw.net/jtv_user_pictures/flosd-channel_header_image-2162bf5c871a74bd-640x125.jpeg", "video_banner"=>"http://static-cdn.jtvnw.net/jtv_user_pictures/flosd-channel_offline_image-79339e326c17b718-640x360.png", "background"=>nil, "profile_banner"=>nil, "profile_banner_background_color"=>nil, "url"=>"http://www.twitch.tv/flosd", "views"=>14808980, "_links"=>{"self"=>"https://api.twitch.tv/kraken/channels/flosd", "follows"=>"https://api.twitch.tv/kraken/channels/flosd/follows", "commercial"=>"https://api.twitch.tv/kraken/channels/flosd/commercial", "stream_key"=>"https://api.twitch.tv/kraken/channels/flosd/stream_key", "chat"=>"https://api.twitch.tv/kraken/chat/flosd", "features"=>"https://api.twitch.tv/kraken/channels/flosd/features", "subscriptions"=>"https://api.twitch.tv/kraken/channels/flosd/subscriptions", "editors"=>"https://api.twitch.tv/kraken/channels/flosd/editors", "teams"=>"https://api.twitch.tv/kraken/channels/flosd/teams", "videos"=>"https://api.twitch.tv/kraken/channels/flosd/videos"}}},
4

1 回答 1

0
json = @twitch.getStreams(game:"League of Legends")[:body][:streams]
JSON.parse(json).values_at('viewers','previews','_links')

干杯!

于 2013-12-02T02:17:50.687 回答