2016-05-23 77 views
0

我想开Python中的JSON文件和我有错误:的UnicodeDecodeError当导入JSON文件

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 64864: ordinal not in range(128)

我的代码非常简单:

# -*- coding: utf-8 -*- 

import json 

with open('birdw3l2.json') as data_file:  
    data = json.load(data_file) 
print(data) 

有人能帮助我吗?谢谢!

回答

0

请尝试下面的代码。

import json 

with open('birdw3l2.json') as data_file:  
    data = json.load(data_file).decode('utf-8') 
print(data) 
+0

不会改变任何事情:( – jiayi

+0

@jiayi尝试更新的一个 –

+0

没有它总是同样的问题。其实,即使我不做打印,错误仍然存​​在...... – jiayi

0

你应该指定你的编码格式,当你加载你的json文件。像这样:

data = json.load(data_file, encoding='utf-8') 

编码取决于您的文件编码。