<p>使用Python 3.5.1,我拉入了一个文本文件,其中每一行都是JSON格式的:
{“a”:“windows”,“b”:“stairs”…}</p>
<pre><code>import json
path = 'folder/data.txt'
records=[json.loads(line) for line in open(path,'rb')]
</code></pre>
<p>但我收到了一个错误:</p>
<pre><code>the JSON object must be str, not 'bytes'
</code></pre>
<p>打印第一行文件没有问题,所以我确信文件路径是正确的。</p>