Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何解析JSON对象中的数据?_Ruby_Json - Fatal编程技术网

Ruby 如何解析JSON对象中的数据?

Ruby 如何解析JSON对象中的数据?,ruby,json,Ruby,Json,我刚刚开始尝试使用JSON web服务,但我在找出获取实际数据元素的最佳方法时遇到了一些困难 我收到一个响应,该响应已使用JSON.parse方法转换为Ruby哈希。散列如下所示: {"response"=>{"code"=>2002, "payload"=>{"topic"=>[{"name"=>"Topic Name", "url"=>"http://www.something.com/topic", "hero_image"=>{"image_id

我刚刚开始尝试使用JSON web服务,但我在找出获取实际数据元素的最佳方法时遇到了一些困难

我收到一个响应,该响应已使用
JSON.parse
方法转换为Ruby哈希。散列如下所示:

{"response"=>{"code"=>2002, "payload"=>{"topic"=>[{"name"=>"Topic Name", "url"=>"http://www.something.com/topic", "hero_image"=>{"image_id"=>"05rfbwV0Nggp8", "hero_image_id"=>"0d600BZ7MZgLJ", "hero_image_url"=>"http://img.something.com/imageserve/0d600BZ7MZgLJ/60x60.jpg"}, "type"=>"PERSON", "search_score"=>10.0, "topic_id"=>"0eG10W4e3Aapo"}]}, "message"=>"Success"}}
我想知道的是,获取“主题”数据的最简单方法是什么,这样我就可以做以下事情:

topic.name = json_resp.name
topic.img = jsob_resp.hero_image_url
etc
你可以使用的。其中一个for ruby使用它,生成的界面非常干净且易于使用。我用不到60行代码就完成了美味的rss api


通常情况下,Twitter会非常清楚地展示如何使用它。

Twitter客户端不再使用Hashie gem,但它仍然是OP要求的最佳选择。