如何使用请求在python中查找响应列表的长度

前端之家收集整理的这篇文章主要介绍了如何使用请求在python中查找响应列表的长度 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用请求库来解析数据,它返回json数据列表
当我试图找到响应列表的长度时,它给出了错误
TypeError:“响应”类型的对象没有len()
我正在使用这种方法

  import requests
r=requests.get('http://localhost:3000/api/Customer')
print(r.status_code)
print(r.text)

x={}
for i in range(0,len(r)):
    x = r.json()[i]
    print(x)

通过使用此即时消息错误
TypeError:“响应”类型的对象没有len()

最佳答案
您应该在r.json()返回的列表对象上使用len:

lst = r.json()
for i in range(len(lst)):
    x = lst[i]
    print(x)

但是,然后您应该简单地遍历列表:

for x in r.json():
    print(x)
原文链接:https://www.f2er.com/python/533175.html

猜你在找的Python相关文章