TypeError: ‘bool’ object is not iterable

json_data = {'success': True, 'code': 0, 'message': None, 'body': {'items': [], 'pager': {'pageIndex': 49, 'pageSize': 12, 'total': 0, 'totalPage': 0, 'sorting': None, 'sortType': 0}}}

# False
serial_names = jsonpath.jsonpath(json_data, '$.body.items[*].productName')  

# 型号
product_models = jsonpath.jsonpath(json_data, '$.body.items[*].manufacturerPartNumber')

for name,model in zip(serial_names, product_models):
    print(name, model)

报错原因分析:

因为返回数据导致 jsonpath 提取失败,此时 serial_names & product_models 的值为False,继而导致 for 循环 in 左边报错

posted @ 2022-12-30 14:06  chuangzhou  阅读(658)  评论(0编辑  收藏  举报