Python | UTF-8 with BOM 编码处理
1、笔者手头有个JSON配置文件,是UTF-8编码的

3、由于编码方式改变,Python代码在读取这个字典时候就会报错


6、整理以后的代码:import jsonimport codecswith open('hdfs.json') as h: content = h.re锾攒揉敫ad() content = content.decode('utf-8-sig') if content.startswith(codecs.BOM_UTF8) else content print json.loads(content,encoding='utf8')

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:36
阅读量:42
阅读量:66
阅读量:34
阅读量:92