我尝试将一个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 "}
如果在我谷歌搜索到的每个例子中,似乎这都起作用了,那么我的错误是什么?
+=
而不是=
... - Haleemur Alidata = json.load(json_data)
。 - Burhan Khalid