我正在尝试解析这个 json 并在 json 中添加新内容。 输入
data ={'11': {'Des Content': ['Update Version', '11: Date of User'],
'Date': ['920221207'],
'service': ['courier']}}
keys=["11","21","13"]
输出
{
"11:":{
"Describe" : "Date of User",
"Data" :{
"Date":["920221207"],
"service":["courier"]
}
}
试试这个
res = {}
for k,v in data.items():
res[k] = {"Describe": v.pop("Des Content")[-1].split(": ")[-1], # remove Des Content and assign Date of User to Describe
"Data": v} # assign the remaining v dict to Data
res
# {'11': {'Describe': 'Date of User',
# 'Data': {'Date': ['920221207'], 'service': ['courier']}}}