json.load,JSONDecodeError:期望值:第1行第1列(字符0)

时间:2020-08-11 03:28:41

标签: python json python-3.x utf-8 decode

我正在读取json.bz2文件。

代码

with open(full_filename, 'r', encoding='utf-8', errors='ignore') as the_file:    
    data = json.load(the_file)

JSONDecodeError:期望值:第1行第1列(字符0)

我尝试在Google上搜索解决方案,但没有一个起作用。

1 个答案:

答案 0 :(得分:0)

您正尝试直接解码压缩的JSON。您需要先将其解压缩。使用bz2 package。例如:

import json
import bz2

# ...

data = json.loads(bz2.BZ2File(full_filename).read().decode())