开发者

How to conver JSON collection into Hash using Rails 3

I am having JSON collection fetched from MongoDB & 开发者_运维知识库I want to convert it into Hash.

How can I do so..?

Thanks in advance..


How did you fetch it from mongo? the ruby mongo driver automatically gives you ruby hashes.

EDIT: To take the second question into account

In mongo, queries don't actually execute until you call something that requires them to execute. Before you call to_json, you actually are still playing with a query object.

Instead of to_json, try just using to_a to get an array of hashes back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜