我有一个包含 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() 方法,但它说不能将数组转换为字符串。
我该怎么做,有什么想法吗?