我是Python新手,试图从json响应中创建一个新结构。两个json响应是来自2个环境的测试,但长度和顺序相同,只是不同的结果,为简洁起见,我简化了示例。压缩两个字典列表
response1.json
[{"qa":"o"}, {"qa":"o"}]
response2.json
[{"prod":"x"}, {"prod": "x"}]
create.py
with open('response1.json') as data_file:
data1 = json.load(data_file)
with open('response2.json') as data_file:
data2 = json.load(data_file)
#i want to be able to create a structure like this:
# [{"qa":"o", "prod":"x"},{"qa":"o", "prod":"x"}]
list = []
#This is wrong but was thinking that logic would be close to this.
for i in range(0,len(data1)):
list[i]['qa'] = data1[i]['qa']
for i in range(0,len(data2)):
list[i]['prod'] = data[i]['prod']
我想** ** respones1.json无效JSON。 – linusg
编辑抱歉,关于那 – teddybear123
固定对不起,再次 – teddybear123