【发布时间】:2012-06-21 12:46:18
【问题描述】:
我有一个包含以下 json 格式信息(新闻提要)的对象:
def index
@news_feed = FeedDetail.find(:all)
@to_return = "<h3>The RSS Feed</h3>"
@news_feed.items.each_with_index do |item, i|
to_return += "#{i+1}.#{item.title}<br/>"
end
render :text => @to_return
end
我只想显示该 json 数组中的特定值,例如标题描述等。当我直接渲染 @news_feed 对象时,它会给出这个
[{
"feed_detail":{
"author":null,
"category":[],
"comments":null,
"converter":null,
"description":"SUNY Levin Institute, Empire State Development Facilitate Collaboration to Drive Economic Opportunities Across New York State",
"do_validate":false,
"enclosure":null,
"guid":null,
"link":"http://www.suny.edu/sunynews/News.cfm?filname=2012-06-20-LevinConferenceRelease.htm",
"parent":null,
"pubDate":"2012-06-20T23:53:00+05:30",
"source":null,
"title":"SUNY Levin Institute, Empire State Development Facilitate Collaboration to Drive Economic Opportunities Across New York State"
}
}]
当遍历 json 对象时,它会给出 - 未定义的方法项。 我想要的只是从该数组中获取特定的值。我也使用了 JSON.parse() 方法,但它说不能将数组转换为字符串。
我该怎么做,知道吗?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3