我正在尝试将一个json文件加载到python中,但没有成功。在过去的几个小时里,我一直在谷歌上搜索一个解决方案,似乎就是无法加载。我尝试使用对每个人都有效的相同的json.load('filename')函数来加载它。我一直收到:"UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in postion 124: invalid continuation byte"
下面是我使用的代码
import json
json_data = open('myfile.json')
for line in json_data:
data = json.loads(line) <--I get an error at this. 下面是我的文件中的一行样例
{"topic":"security","question":"Putting the Biba-LaPadula Mandatory Access Control Methods to Practise?","excerpt":"Text books on database systems always refer to the two Mandatory Access Control models; Biba for the Integrity objective and Bell-LaPadula for the Secrecy or Confidentiality objective.\n\nText books ...\r\n "}如果在我用谷歌搜索的每个例子中,这似乎对每个人都有效,那么我的错误是什么?
发布于 2014-12-07 15:20:24
您是否尝试过:
json.loads(line.decode("utf-8"))这里提出了类似的问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2
编辑:如果上述方法不起作用,
json.loads(line.decode("utf-8","ignore"))将要。
https://stackoverflow.com/questions/27340542
复制相似问题