浏览 3689 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-04-13
xml.instruct! :xml, :version => "1.0", :encoding => "GB2312" headers['Content-Type'] = 'text/xml; character=GB2312' 这些都做了,但是输出总是乱码,不能正确输出中文。何故? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-04-14
$KCODE = 'GB2312'
require 'jcode' 試試看? |
|
返回顶楼 | |
发表时间:2007-04-16
呵呵。没有用啦。
|
|
返回顶楼 | |
发表时间:2008-04-01
在rails中么?我也遇到同样的问题,查看了原代码,发现在
C:\ruby\lib\ruby\gems\1.8\gems\activesupport-2.0.2\lib\active_support\multibyte\chars.rb 中有说明,缺省的multibyte字符串handler是按utf8来处理的。应该需要自己hack代码。 # Chars enables you to work transparently with multibyte encodings in the Ruby String class without having extensive # knowledge about the encoding. A Chars object accepts a string upon initialization and proxies String methods in an # encoding safe manner. All the normal String methods are also implemented on the proxy. # # String methods are proxied through the Chars object, and can be accessed through the +chars+ method. Methods # which would normally return a String object now return a Chars object so methods can be chained. # # "The Perfect String ".chars.downcase.strip.normalize #=> "the perfect string" # # Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made. # If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them. # # bad.explicit_checking_method "T".chars.downcase.to_s # # The actual operations on the string are delegated to handlers. Theoretically handlers can be implemented for # any encoding, but the default handler handles UTF-8. This handler is set during initialization, if you want to # use you own handler, you can set it on the Chars class. Look at the UTF8Handler source for an example how to # implement your own handler. If you your own handler to work on anything but UTF-8 you probably also # want to override Chars#handler. # # ActiveSupport::Multibyte::Chars.handler = MyHandler # # Note that a few methods are defined on Chars instead of the handler because they are defined on Object or Kernel # and method_missing can't catch them. |
|
返回顶楼 | |