Encoding::UndefinedConversionError

后端 未结 5 598
天命终不由人
天命终不由人 2020-12-13 09:09

I keep getting an Encoding::UndefinedConversionError - "\\xC2" from ASCII-8BIT to UTF-8 every time I try to convert a hash into a JSON string. I tried

5条回答
  •  無奈伤痛
    2020-12-13 09:50

    menu.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
    

    This worked perfectly, I had to replace some extra characters but there are no more errors.

提交回复
热议问题