我在windows上使用搅拌器,遵循教程:在搅拌机中可视化JSON数据,但我无法打开JSON文件。
我的代码(窗口):
import json
with open('C:\Users\Franktabs\Documents\export.json') as f:
j = json.load(f)
print(j)他的代码(Linux):
import json
with open('/home/chris/Downalds/tutorial.son') as f:
j = json.load(f)
print(j)错误信息:
Python: File "C:\Users\Franktabs\Documents\Json2.blend\My Script", line 3
with open('C:\Users\Franktabs\Documents\export.json') as f:
^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
location: <unknown location>:-1已尝试的解决办法:
发布于 2021-09-07 16:57:49
如前所述,\U是一个unicode转义字符,很可能是问题的一部分。没有看到\\的使用或r''代码或错误,很难知道有什么问题.
这应该适用于与操作系统无关的解决方案,假设您有一个文件所在的文档目录。
import json
import pathlib
with open(pathlib.Path.home() / 'Documents' / 'export.json') as f:
data = json.load(f)https://stackoverflow.com/questions/69091511
复制相似问题