Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
yajl-ruby で json ファイルを解析する際に問題が発生しました。次のようなエラーが表示されます。
'parse': lexical error: invalid char in json text. (Yajl::ParseError)
{ "inquiry": { " (right here) ------^
明示的に utf-8 エンコーディングでファイルを開こうとしましたが、役に立ちません。中括弧でエラーが発生するという奇妙な部分。
その理由は、BOM 付きの UTF-8 でエンコードされたファイルを開いたためです。このエラーを修正するには、次のオプションでファイルを開く必要がありました。
File.open(@file, 'r:bom|utf-8')