我是一个学习编程、python和这个论坛的新手。我想在VS Code加载一个json文件,并从它得到一些数据在excel中使用它。但是当我开始写
时,它就是无法加载。我写这段代码来查看json文件。
import json
with open("18july.json") as f:
jsondata = json.load(f)
print(jsondata)
当我运行py文件时,它写在终端
PS C:UsersmonstDownloadspython files> & C:/Users/monst/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/monst/Downloads/python files/tidyjson.py"
Traceback (most recent call last):
File "c:UsersmonstDownloadspython filestidyjson.py", line 4, in <module>
jsondata = json.load(f)
File "C:UsersmonstAppDataLocalProgramsPythonPython310libjson__init__.py", line 293, in load
return loads(fp.read(),
File "C:UsersmonstAppDataLocalProgramsPythonPython310libencodingscp1254.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1502: character maps to <undefined>
你可以在下面的链接中下载我附加的json和py文件。也是我的VS Code截图,当我运行它。https://filetransfer.io/data-package/64l6xzJS
谢谢你的兴趣。谢谢你。
一个解决方案:
import json
from pathlib import Path
filepath = Path("18july.json")
jsondata = json.loads(filepath.read_bytes())
print(jsondata)