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')
