如何使用列表中的python相邻键解析嵌套Json[重复]

问题描述 投票:0回答:1

我正在尝试解析这个 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"]
  }   
}
python json list parsing
1个回答
0
投票

试试这个

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']}}}
© www.soinside.com 2019 - 2024. All rights reserved.