我遇到這樣的如何在ruby中打印雙層hash?
{"num"=>"219", "id"=>"219", "name"=>"219", "key"=>"", "ps"=>["ˈɑ:bitrəri", "ˈɑrbɪˌtrɛri"], "sent"=>[{"orig"=>"\nHe makes unpredictable, decisions.\n", "trans"=>"\his decision is very hard to understand \n"}, {"orig"=>"\nYou can make an choice.\n", "trans"=>"\n you can chose randomly。\n"}]}
我只是想打印這個哈希的一部分的哈希值。
我的解決辦法是
key = ['key','ps','sent']
key.each{|key| key == 'sent' ? (p server_config["sent"].to_s) : (p server_config[key])}
它不能很好地工作。 二級哈希打印這樣
[{\"orig\"=>\"\\nAs soon as he kicked the bucket, he started to become famous.\\n\", \"trans\"=>\"\\nhe die and he became famous \\n\"}, ]"
如何打印此兩級哈希以及
我想就像下面的輸出。
As soon as he kicked the bucket, he started to become famous.
he die and he became famous.
什麼不好? –
二級哈希打印這樣的[{\「原稿\」 => \「\\ NAS甫一翹辮子了,他開始成名。\\ñ\」,\「反式\」 => \」 \\ NHE死,他成爲著名的\\ñ\「}]」 – user1396000
你期望的輸出? –