【发布时间】:2020-02-19 08:55:02
【问题描述】:
我想创建一个可以用作配置文件的json文件。我有来自多家公司的不同文件,它们以不同的列名报告相同的信息。
我想使用 json 文件中提供的信息来运行 python 脚本,以将来自所有文件和公司的所有信息合并到一个主文件中。
结构如下:
{"companies":
{"company1": [
{"path": "C:/USER/Path/Company1/",
"files": [
{
{"_CO": {"ID": "ID", "Report Number": "Report_Number"}},
{"_TR": {"ID": "Trade_Ident", "Report Number": "Number of Report"}},
},
],
},
],
},
{"company2": [
{"path": "C:/USER/Path/Company2/",
"files": [
{
{"_CO": {"ID": "Identification", "Report Number": "Report-Number"}},
{"_TR": {"ID": "Ident", "Report Number": "NumberReport"}},
},
],
},
],
},
},
但是,我在尝试读取 python 中的 .json 时收到以下错误。
json.decoder.JSONDecodeError:期望属性名称包含在 双引号:第 6 行第 5 列(char 90)
读取我使用的文件:
import json
path = "/user_folder/USER/Desktop/Data/"
file = "ConfigFile.json"
with open(path+file) as f:
my_test = json.load(f)
感谢您的帮助,因为我无法找出文件结构中的错误。
【问题讨论】: