Home  >  Q&A  >  body text

Ruby散列中保存中文,使用puts输出时只能显示unicode码,请问如何显示中文?

Ruby散列中保存中文,使用puts输出时只能显示unicode码,请问如何显示中文?

源码:

hash={a:"第一条",b:"第二条",c:"第三条"}
puts hash

输出结果:

{:a=>"\u7B2C\u4E00\u6761", :b=>"\u7B2C\u4E8C\u6761", :c=>"\u7B2C\u4E09\u6761"}
黄舟黄舟2710 days ago610

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-24 09:16:09

    Open irb input

    Encoding.locale_charmap

    Check if your encoding is => "UTF-8"

    The Ruby version must be greater than 1.8

    Check whether you have readline installed

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-24 09:16:09

    Warning: Trying to solve a non-existent problem.

    reply
    0
  • 怪我咯

    怪我咯2017-04-24 09:16:09

    I tested it on CentOS and Mac and didn’t find the problem you mentioned.

    reply
    0
  • Cancelreply