我有一本字典在下面
{
"aggregations": {
"A": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{ "key": "ADL", "doc_count": 1 },
{ "key": "SDD", "doc_count": 1 },
{ "key": "JJD", "doc_count": 1 }
]
},
"B": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{ "key": "ABC", "doc_count": 1 },
{ "key": "CDE", "doc_count": 1 },
{ "key": "FGH", "doc_count": 1 }
]
},
"C": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{ "key": "XYX", "doc_count": 1 },
{ "key": "NXS", "doc_count": 1 }
]
}
}
}
aggregations.keys将是aggregationfilters.fieldName
aggregations.bucket.key将是aggregationfilters.values.title
aggregationfilters.values.paragration每次都为null
aggregations.bucket.doc\u计数将是aggregationfilters.values.count
基本上,我需要提取aggregations.keys和aggregations.bucket值并放入不同的字典中
需要编写一个通用的代码结构来实现这一点
我不能用.弹出(重命名)字典
我的预期出局了
{
"aggregationfilters": [
{
"name": "ABC",
"fieldName": "A",
"values": [
{ "title": "ADL", "paragraph": null, "count": 1 },
{ "title": "SDD", "paragraph": null, "count": 1 },
{ "title": "JJD", "paragraph": null, "count": 1 }
]
}, {
"name": "CDE",
"fieldName": "B",
"values": [
{ "title": "ABC", "paragraph": null, "count": 1 },
{ "title": "CDE", "paragraph": null, "count": 1 },
{ "title": "FGH", "paragraph": null, "count": 1 }
]
}, {
"name": "FGH",
"fieldName": "C",
"values": [
{ "title": "XYX", "paragraph": null, "count": 1 },
{ "title": "NXS", "paragraph": null, "count": 1 }
]
}
]
}
好吧,这是可行的,但即使我尽了最大努力,这看起来还是不干净
输出:
始终显示您的代码,若这是一个有效的代码,那个就太好了——表明您已经在您的问题上付出了至少那个么值得的努力
我不觉得麻烦,因为这感觉像是解谜,但其他人可能不会
相关问题 更多 >
编程相关推荐