我在ruby中定义哈希数组时遇到问题。我找到了一些解决方案,但没有人回答这个小代码示例的错误:
users = [{:id => "1", :imie => "Szymon", :punkty => "0"},
{:id => "2", :imie => "Krzysiek", :punkty => "0"},
{:id => "3", :imie => "Przemek", :punkty => "0"},
{:id => "4", :imie => "Paweł", :punkty => "0"}]
谢谢!
答案 0 :(得分:2)
此条目的问题 - :imie => "Paweł"
。 无效的多字节字符(US-ASCII)
像这样使用:
# encoding: UTF-8
users = [{:id => "1", :imie => "Szymon", :punkty => "0"},
{:id => "2", :imie => "Krzysiek", :punkty => "0"},
{:id => "3", :imie => "Przemek", :punkty => "0"},
{:id => "4", :imie => "Paweł", :punkty => "0"}]
p users.class #=>Array
使用以下内容:
Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8'