Unexpected UTF-8 BOM (decode using utf-8-sig)

  • 摘自网站
  • 摘要:问题描述:json.loads(text,encoding='utf8')报UnexpectedUTF-8BOM(decodeusingutf-8-sig)错误,将encoding改为'utf-8-sig'仍然报错。原因分析:text包含BOM字符解决方案:将BOM头去掉

  • 问题描述:

    json.loads(text,encoding='utf8') 报Unexpected UTF-8 BOM (decode using utf-8-sig)错误,将encoding改为'utf-8-sig'仍然报错。

    原因分析:

    text包含BOM字符

    解决方案:

    将BOM头去掉,代码如下:

 if text.startswith(u'/ufeff'):
    text = text.encode('utf8')[3:].decode('utf8')

你可能感兴趣的:(Unexpected UTF-8 BOM (decode using utf-8-sig))