小编Gre*_*reg的帖子

JSON对象必须是str,而不是'bytes'

使用Python 3.5.1,我提取了一个文本文件,其中每一行都是JSON格式:{"a":"windows","b":"stairs"......}

import json
path = 'folder/data.txt'
records=[json.loads(line) for line in open(path,'rb')]
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误:

the JSON object must be str, not 'bytes'
Run Code Online (Sandbox Code Playgroud)

我打印第一行文件没有问题,所以我确信文件路径是正确的.

python import text json

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

import ×1

json ×1

python ×1

text ×1