鱼C论坛

 找回密码
 立即注册
查看: 2222|回复: 8

[已解决]字典嵌套字典如何层层解开获取里面的数据

[复制链接]
发表于 2023-2-7 14:09:57 | 显示全部楼层 |阅读模式
50鱼币
dict = {
        'result': {
                'categorys': [{
                        'categorynum': '001',
                        'count': '55',
                        'categoryname': '重庆公共资源'
                }],
                'totalcount': 55,
                'records': [{
                        'pubinwebdate': '2022-10-11 17:54:26',
                        'titlenew': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infoa': '',
                        'title': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infod': '50000120220708001030101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6592031',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 17:54:25',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc6f8bf56-5b35-4391-bb06-3ba25aeccecb004002002010_001',
                        'sysscore': '0',
                        'categorynum': '004002002010',
                        'infoid': 'c6f8bf56-5b35-4391-bb06-3ba25aeccecb',
                        'categorytype2': '答疑补遗',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 17:54:26'
                }, {
                        'pubinwebdate': '2022-10-11 16:19:05',
                        'titlenew': '茶惠大道二标段检测工程的中标候选人公示',
                        'infoa': '',
                        'title': '茶惠大道二标段检测工程的中标候选人公示',
                        'infod': '50000120220913025090101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6591187',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 00:00:00',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc5ab4832-7c72-4465-bb44-e2663fb6c007004002003002_001',
                        'sysscore': '0',
                        'categorynum': '004002003002',
                        'infoid': 'c5ab4832-7c72-4465-bb44-e2663fb6c007',
                        'categorytype2': '中标候选人公示',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 16:20:26'
                }, {
                        'pubinwebdate': '2023-01-13 16:32:13',
                        'titlenew': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infoa': '',
                        'title': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infod': '5002262038943582210100025',
                        'infoc': '荣昌区',
                        'categorytype': '中介超市',
                        'content': '',
                        'rowid': '7137421',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-10 09:28:34',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyPNII_5002262038943582210100025004010001_001',
                        'sysscore': '0',
                        'categorynum': '004010001',
                        'infoid': 'PNII_5002262038943582210100025',
                        'categorytype2': '采购公告',
                        'zhuanzai': '',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-10 09:28:34',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2023-01-13 16:32:13'
                }],
                'scorllId': '0;0;1665394114000;7137421;',
                'executetime': '0.245'
        }
}
dict1=(dict.values())
多层字典嵌套的数据,请问如何解开是最快捷的方法,感谢大佬们了
最佳答案
2023-2-7 14:09:58
uupppo 发表于 2023-2-7 14:10
我现在需要'titlenew'和'infod'的值

data = {
        'result': {
                'categorys': [{
                        'categorynum': '001',
                        'count': '55',
                        'categoryname': '重庆公共资源'
                }],
                'totalcount': 55,
                'records': [{
                        'pubinwebdate': '2022-10-11 17:54:26',
                        'titlenew': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infoa': '',
                        'title': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infod': '50000120220708001030101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6592031',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 17:54:25',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc6f8bf56-5b35-4391-bb06-3ba25aeccecb004002002010_001',
                        'sysscore': '0',
                        'categorynum': '004002002010',
                        'infoid': 'c6f8bf56-5b35-4391-bb06-3ba25aeccecb',
                        'categorytype2': '答疑补遗',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 17:54:26'
                }, {
                        'pubinwebdate': '2022-10-11 16:19:05',
                        'titlenew': '茶惠大道二标段检测工程的中标候选人公示',
                        'infoa': '',
                        'title': '茶惠大道二标段检测工程的中标候选人公示',
                        'infod': '50000120220913025090101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6591187',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 00:00:00',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc5ab4832-7c72-4465-bb44-e2663fb6c007004002003002_001',
                        'sysscore': '0',
                        'categorynum': '004002003002',
                        'infoid': 'c5ab4832-7c72-4465-bb44-e2663fb6c007',
                        'categorytype2': '中标候选人公示',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 16:20:26'
                }, {
                        'pubinwebdate': '2023-01-13 16:32:13',
                        'titlenew': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infoa': '',
                        'title': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infod': '5002262038943582210100025',
                        'infoc': '荣昌区',
                        'categorytype': '中介超市',
                        'content': '',
                        'rowid': '7137421',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-10 09:28:34',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyPNII_5002262038943582210100025004010001_001',
                        'sysscore': '0',
                        'categorynum': '004010001',
                        'infoid': 'PNII_5002262038943582210100025',
                        'categorytype2': '采购公告',
                        'zhuanzai': '',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-10 09:28:34',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2023-01-13 16:32:13'
                }],
                'scorllId': '0;0;1665394114000;7137421;',
                'executetime': '0.245'
        }
}


records = data['result']['records']
for i in records:
    print(f'titlenew: {i["titlenew"]}')
    print(f'infod: {i["infod"]}')
    print('-' * 100)

最佳答案

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-2-7 14:09:58 | 显示全部楼层    本楼为最佳答案   
uupppo 发表于 2023-2-7 14:10
我现在需要'titlenew'和'infod'的值

data = {
        'result': {
                'categorys': [{
                        'categorynum': '001',
                        'count': '55',
                        'categoryname': '重庆公共资源'
                }],
                'totalcount': 55,
                'records': [{
                        'pubinwebdate': '2022-10-11 17:54:26',
                        'titlenew': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infoa': '',
                        'title': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infod': '50000120220708001030101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6592031',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 17:54:25',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc6f8bf56-5b35-4391-bb06-3ba25aeccecb004002002010_001',
                        'sysscore': '0',
                        'categorynum': '004002002010',
                        'infoid': 'c6f8bf56-5b35-4391-bb06-3ba25aeccecb',
                        'categorytype2': '答疑补遗',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 17:54:26'
                }, {
                        'pubinwebdate': '2022-10-11 16:19:05',
                        'titlenew': '茶惠大道二标段检测工程的中标候选人公示',
                        'infoa': '',
                        'title': '茶惠大道二标段检测工程的中标候选人公示',
                        'infod': '50000120220913025090101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6591187',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 00:00:00',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc5ab4832-7c72-4465-bb44-e2663fb6c007004002003002_001',
                        'sysscore': '0',
                        'categorynum': '004002003002',
                        'infoid': 'c5ab4832-7c72-4465-bb44-e2663fb6c007',
                        'categorytype2': '中标候选人公示',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 16:20:26'
                }, {
                        'pubinwebdate': '2023-01-13 16:32:13',
                        'titlenew': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infoa': '',
                        'title': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infod': '5002262038943582210100025',
                        'infoc': '荣昌区',
                        'categorytype': '中介超市',
                        'content': '',
                        'rowid': '7137421',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-10 09:28:34',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyPNII_5002262038943582210100025004010001_001',
                        'sysscore': '0',
                        'categorynum': '004010001',
                        'infoid': 'PNII_5002262038943582210100025',
                        'categorytype2': '采购公告',
                        'zhuanzai': '',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-10 09:28:34',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2023-01-13 16:32:13'
                }],
                'scorllId': '0;0;1665394114000;7137421;',
                'executetime': '0.245'
        }
}


records = data['result']['records']
for i in records:
    print(f'titlenew: {i["titlenew"]}')
    print(f'infod: {i["infod"]}')
    print('-' * 100)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-7 14:10:52 | 显示全部楼层
我现在需要'titlenew'和'infod'的值
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-2-7 15:06:33 | 显示全部楼层
本帖最后由 isdkz 于 2023-2-7 15:07 编辑

data = {
        'result': {
                'categorys': [{
                        'categorynum': '001',
                        'count': '55',
                        'categoryname': '重庆公共资源'
                }],
                'totalcount': 55,
                'records': [{
                        'pubinwebdate': '2022-10-11 17:54:26',
                        'titlenew': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infoa': '',
                        'title': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infod': '50000120220708001030101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6592031',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 17:54:25',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc6f8bf56-5b35-4391-bb06-3ba25aeccecb004002002010_001',
                        'sysscore': '0',
                        'categorynum': '004002002010',
                        'infoid': 'c6f8bf56-5b35-4391-bb06-3ba25aeccecb',
                        'categorytype2': '答疑补遗',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 17:54:26'
                }, {
                        'pubinwebdate': '2022-10-11 16:19:05',
                        'titlenew': '茶惠大道二标段检测工程的中标候选人公示',
                        'infoa': '',
                        'title': '茶惠大道二标段检测工程的中标候选人公示',
                        'infod': '50000120220913025090101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6591187',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 00:00:00',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc5ab4832-7c72-4465-bb44-e2663fb6c007004002003002_001',
                        'sysscore': '0',
                        'categorynum': '004002003002',
                        'infoid': 'c5ab4832-7c72-4465-bb44-e2663fb6c007',
                        'categorytype2': '中标候选人公示',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 16:20:26'
                }, {
                        'pubinwebdate': '2023-01-13 16:32:13',
                        'titlenew': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infoa': '',
                        'title': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infod': '5002262038943582210100025',
                        'infoc': '荣昌区',
                        'categorytype': '中介超市',
                        'content': '',
                        'rowid': '7137421',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-10 09:28:34',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyPNII_5002262038943582210100025004010001_001',
                        'sysscore': '0',
                        'categorynum': '004010001',
                        'infoid': 'PNII_5002262038943582210100025',
                        'categorytype2': '采购公告',
                        'zhuanzai': '',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-10 09:28:34',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2023-01-13 16:32:13'
                }],
                'scorllId': '0;0;1665394114000;7137421;',
                'executetime': '0.245'
        }
}


records = data['result']['records']
for i in records:
    print(f'titlenew: {i["titlenew"]}')
    print(f'infod: {i["infod"]}')
    print('-' * 100)
    
    
    
    
    
    
    
    
    
    
# 下面这段代码用来快速获取键的结构
def get_json_struct(dic, start='', result=[]):
    if isinstance(dic, dict):
        for k in dic:
            get_json_struct(dic[k], f'{start}.{k}', result)
    elif isinstance(dic, tuple) or isinstance(dic, list):
        for i, each in enumerate(dic):
            get_json_struct(each, f'{start}.{i}->index', result)
    else:
        result.append(start[1:])
    return result



titlenews = []
infods = []

for i in get_json_struct(data):
    if 'titlenew' in i:
        titlenews.append(i)
    if 'infod' in i:
        infods.append(i)


print('-' * 100)
print("""
    包含 titlenews 和 infods 的索引结构,其中 ->index 表示这个是列表或元组的索引,而不是字典的键,如无 -> index即为字典的键
""")
print()
print('titlenews:', titlenews)
print()
print('infods:', infods)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-7 15:14:24 | 显示全部楼层

确实可以显示了,但是我没看懂代码,有相应的解析教程吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-2-7 15:18:33 | 显示全部楼层
uupppo 发表于 2023-2-7 15:14
确实可以显示了,但是我没看懂代码,有相应的解析教程吗

如果不是很复杂的结构的话自己来一层一层判断它的键就好了,

我没有发现有什么可以剖析字典的层次结构的库,所以写了个递归函数来判断,

递归函数确实不好理解,也不好讲清楚
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-7 15:46:37 | 显示全部楼层
isdkz 发表于 2023-2-7 15:18
如果不是很复杂的结构的话自己来一层一层判断它的键就好了,

我没有发现有什么可以剖析字典的层次结构 ...
import json
dict = {
        'result': {
                'categorys': [{
                        'categorynum': '001',
                        'count': '55',
                        'categoryname': '重庆公共资源'
                }],
                'totalcount': 55,
                'records': [{
                        'pubinwebdate': '2022-10-11 17:54:26',
                        'titlenew': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infoa': '',
                        'title': '重庆市食品药品检验检测研究院迁(扩)建项目(二期)电梯采购及安装工程答疑补遗文件',
                        'infod': '50000120220708001030101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6592031',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 17:54:25',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc6f8bf56-5b35-4391-bb06-3ba25aeccecb004002002010_001',
                        'sysscore': '0',
                        'categorynum': '004002002010',
                        'infoid': 'c6f8bf56-5b35-4391-bb06-3ba25aeccecb',
                        'categorytype2': '答疑补遗',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 17:54:26'
                }, {
                        'pubinwebdate': '2022-10-11 16:19:05',
                        'titlenew': '茶惠大道二标段检测工程的中标候选人公示',
                        'infoa': '',
                        'title': '茶惠大道二标段检测工程的中标候选人公示',
                        'infod': '50000120220913025090101',
                        'infoc': '市级',
                        'categorytype': '工程招投标',
                        'content': '',
                        'rowid': '6591187',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-11 00:00:00',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyc5ab4832-7c72-4465-bb44-e2663fb6c007004002003002_001',
                        'sysscore': '0',
                        'categorynum': '004002003002',
                        'infoid': 'c5ab4832-7c72-4465-bb44-e2663fb6c007',
                        'categorytype2': '中标候选人公示',
                        'zhuanzai': '来源于电子招投标系统',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-11 23:59:59',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2022-10-11 16:20:26'
                }, {
                        'pubinwebdate': '2023-01-13 16:32:13',
                        'titlenew': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infoa': '',
                        'title': '关于为【国家畜牧科技城公共实训职教基地(荣昌职教中心工程二期)材料检测服务】 公开选取【工程招标代理】机构的公告',
                        'infod': '5002262038943582210100025',
                        'infoc': '荣昌区',
                        'categorytype': '中介超市',
                        'content': '',
                        'rowid': '7137421',
                        'highlight': {},
                        'score': None,
                        'istop': '0',
                        'kaibiaodate': '2022-10-10 09:28:34',
                        'syscollectguid': 'a2861e5f-8e5d-403d-b746-8abea733b966',
                        'id': 'cqggzyPNII_5002262038943582210100025004010001_001',
                        'sysscore': '0',
                        'categorynum': '004010001',
                        'infoid': 'PNII_5002262038943582210100025',
                        'categorytype2': '采购公告',
                        'zhuanzai': '',
                        'sysclicktimes': 0,
                        'ordernum': '0',
                        'webdate': '2022-10-10 09:28:34',
                        'projectno': '',
                        'customtitle': '',
                        'syscategory': '001',
                        'linkurl': '',
                        'tktype': '',
                        'infodate': '2023-01-13 16:32:13'
                }],
                'scorllId': '0;0;1665394114000;7137421;',
                'executetime': '0.245'
        }
}
a=list((dict['result']['records']))
for i in a:
        print(i)
        for b in i:
                b=i['titlenew']
                print(b)
大佬递归函数有点复杂,我自己看了下有个见到那的代码可以解决,但是我在使用的时候print(b)出现了很多行,想问问是哪里出了问题
无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-2-7 15:50:44 | 显示全部楼层
uupppo 发表于 2023-2-7 15:46
大佬递归函数有点复杂,我自己看了下有个见到那的代码可以解决,但是我在使用的时候print(b)出现了很多 ...

我那个递归函数只是为了获取结构的,不是获取值的,获取值根本不需要用到递归函数

你那个代码
for i in a:
        print(i)
        for b in i:
                b=i['titlenew']
                print(b)

改成

for i in a:
     b=i['titlenew']
     print(b)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-2-7 16:01:57 | 显示全部楼层
isdkz 发表于 2023-2-7 15:50
我那个递归函数只是为了获取结构的,不是获取值的,获取值根本不需要用到递归函数

你那个代码

感谢大佬了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-24 17:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表