第一个文件
{
"data": [
{
"id": "123456",
"create_time": "2016-03-28 11:41:00",
"phone": "138888****",
"name": "路人甲",
},
{
"id": "456789",
"create_time": "2016-03-30 11:41:00",
"phone": "138888****",
"name": "炮兵灰",
},
.....
........
]
}
第二个文件
{
"data": [
"id": "123456",
"driver": "2016-03-28",
"work": "你好",
"type": "A",
},
{
"id": "456789",
"driver": "2016-03-28",
"work": "不好",
"type": "B",
},
.....
........
]
}
第三个文件
{
"data": [
"id": "123456",
"service_distance": "111.22",
"amount": "3.333",
"strive_cnt": "0",
},
{
"id": "123456",
"service_distance": "111.22",
"amount": "3.333",
"strive_cnt": "0",
},
.....
........
]
}
这个时候
我应该怎么写脚本
让几个特定的json参数排序好 集合在一起
生成一个全新的json
比如我只要其中的 id name phone work amount
重组在一个json
import json
jsonOne = {
"data": [
{
"id": "123456",
"create_time": "2016-03-28 11:41:00",
"phone": "138888****",
"name": "aaa"
},
{
"id": "456789",
"create_time": "2016-03-30 11:41:00",
"phone": "138888****",
"name": "bbb"
}
]
}
jsonTwo = {
"data": [
{
"id": "123456",
"driver": "2016-03-28",
"work": "work1",
"type": "A"
},
{
"id": "456789",
"driver": "2016-03-28",
"work": "work2",
"type": "B"
}
]
}
newJson = {
"data": []
}
for index,item in enumerate(jsonOne['data']):
newObj = {
"id": item["id"],
"create_time": item["create_time"],
"phone": item["phone"],
"name": item["name"],
"driver": jsonTwo["data"][index]["driver"],
"work": jsonTwo["data"][index]["work"],
"type": jsonTwo["data"][index]["type"]
};
newJson["data"].append(newObj)
print(newJson["data"]);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。