问题描述
我正在尝试使用 json
中的 json library
打开 Python 3.8
文件,但没有成功。
这是我的 MWE:
with open(pbit_path + file_name,'r') as f:
data = json.load(f)
print(data)
其中 pbit_path
和 file_name
是 .json
文件的绝对路径。例如,这是我尝试打开的 .json
文件示例。
https://github.com/pwnaoj/desktop-tutorial/blob/master/DataModelSchema.json
返回错误
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
我也尝试过使用函数 loads()
、dump()
、dumps()
。
我感谢任何建议
提前致谢。
解决方法
我找到了解决问题的方法。原则上,这是一个编码问题,因为我尝试读取的文件类型是用 python
编码的,所以在 with open(file,mode='r',encoding='utf_16_le') as file:
data = file.read()
data = json.loads(data)
file.close()
SELECT participantId,SUM(`tableName` = 'ExperienceSampling') as cnt
FROM log
GROUP BY `participantId`
ORDER BY cnt ASC ;