"data":{ "12321":[ { "code":"1213", "codename":"13213" } ], "12321.1213":[ { "code":"1321", "codename":"1321" } ], "12@aa米":[ { "code":"12@", "codename":"ss米" } ], "12@aa米.12@":[ { "code":"", "codename":"" } ],怎样获取data里面所有的code和codename,不用根据data[12321]来获取响应的数据
时间: 2023-08-05 09:05:44 浏览: 260
您可以使用循环遍历来获取data中所有的code和codename。以下是一个示例代码:
```python
data = {
"12321": [
{
"code": "1213",
"codename": "13213"
}
],
"12321.1213": [
{
"code": "1321",
"codename": "1321"
}
],
"12@aa米": [
{
"code": "12@",
"codename": "ss米"
}
],
"12@aa米.12@": [
{
"code": "",
"codename": ""
}
]
}
all_codes = []
all_codenames = []
for key in data:
for item in data[key]:
code = item['code']
codename = item['codename']
all_codes.append(code)
all_codenames.append(codename)
print(all_codes)
print(all_codenames)
```
这样,您将获得所有的code和codename,存储在`all_codes`和`all_codenames`列表中。
阅读全文