【发布时间】:2018-12-19 17:37:49
【问题描述】:
设置:
这个数据集有 50 个“问题”,在这些“问题”中,我已经捕获了我需要然后放入我的 postgresql 数据库的数据。但是当我到达“组件”时,我遇到了麻烦。我能够获得“组件”的所有“名称”的列表,但只想为每个“问题”拥有 1 个“名称”实例,其中一些有 2 个。有些是空的,想为那些。
以下是一些足够的示例数据:
{
"issues": [
{
"key": "1",
"fields": {
"components": [],
"customfield_1": null,
"customfield_2": null
}
},
{
"key": "2",
"fields": {
"components": [
{
"name": "Testing"
}
],
"customfield_1": null,
"customfield_2": null
}
},
{
"key": "3",
"fields": {
"components": [
{
"name": "Documentation"
},
{
"name": "Manufacturing"
}
],
"customfield_1": null,
"customfield_2": 5
}
}
]
}
我正在寻找返回(仅用于组件名称):
['null', 'Testing', 'Documentation']
我将其他数据设置为进入数据库,如下所示:
values = list((item['key'],
//components list,
item['fields']['customfield_1'],
item['fields']['customfield_2']) for item in data_story['issues'])
我想知道是否有一种可能的方法可以进入我在上面评论过“组件列表”的已创建组件列表中
只是为了回顾一下,我希望每个问题只有 1 个组件名称是否为 null,并且能够将其与其余数据一起放入 values 变量中。组件中的第一个 name 也适用于每个“问题”
【问题讨论】:
-
“只希望每个“问题”有 1 个“名称”实例”是什么意思。你想去掉一个还是展平它,以便一个“名称”返回两个值?
-
我希望一个不被放入列表中,所以对于每个“问题”我只得到一个组件名称
标签: python json python-3.x