Rails:如何从JSON提取值 [英] Rails: How to extract values from JSON
本文介绍了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)
这篇关于Rails:如何从JSON提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文