Rails:如何从JSON提取值
问题描述:
一个非常简单的问题(我是初学者).我有一个来自fb的JSON响应,其中包含名称和ID:
Very simple question (I am beginner). I have a JSON response from fb containing names and ids:
[{"name"=>"John Kline", "id"=>"10276192"}, {"name"=>"Quinn Kumbers",
"id"=>"18093781"}, {"name"=>"Dan Jacobs", "id"=>"100000918716828"}] ...
如何在我的rails应用程序中提取并访问此数据,同时保留其结构?我想告诉Rails-给我第二个条目的ID",或者给我第275个条目"-这些东西.
How do I extract and access this data in my rails app while preserving its structure? I'd like to be able to tell rails - "give me the id of the 2nd entry", or, "give me the 275th entry" - these sorts of things.
回答时,请假设自己不知道.谢谢!
Please assume no knowledge when answering. thx!
答
,不包含其他任何宝石:
without any other gems:
ActiveSupport::JSON.decode(your_json)