【发布时间】:2013-04-25 04:45:43
【问题描述】:
为了解决problem with YAML incompatibility,我正在尝试用Ruby 编写一个命令行脚本。问题在于我对 Ruby 完全不熟悉。
所以我制作了以下脚本:
require 'json'
require 'yaml'
thing = YAML.load('---
author_id:
- 0
- 1
subject:
- ""
- !binary |
0KHQtNC10LvQsNGC0Ywg0LPRgNCw0LzQvtGC0L3Ri9C5INCy0L3QtdGI0L3Q
uNC5INCy0LjQtCDQtNC70Y8g0LjQvNC10Y7RidC10LPQvtGB0Y8=
')
puts thing.to_json
# puts thing['subject'][1].to_json # Issues the same error
现在我得到了 yaml2json.rb:15:inencode': "\xD0" 从 ASCII-8BIT 到 UTF-8 (Encoding::UndefinedConversionError)`
如何让它认为解码后的 base64 是 UTF-8?一般我不知道某个键的确切名称,subject 只是一个例子。
【问题讨论】:
标签: ruby