[英]Iterating specific values from a json response with Python
I am receiving a python dict that has the following format via curl.我通过 curl 收到具有以下格式的 python 字典。
json = connect(header, URL)
I am trying to iterate/get the different "number" values with the following code:我正在尝试使用以下代码迭代/获取不同的“数字”值:
for i in json['mail']['number']:
print (str(i).replace('"',''))
but it does not work.但它不起作用。 Any ideas?
有任何想法吗?
You're iterating over the wrong object, try this:您正在迭代错误的 object,试试这个:
for i in json['mail']:
print(int(i['number']))
Please also note: naming a variable json
could be very bad because most likely you are using the json
package as well and this will lead to naming conflicts.另请注意:命名变量
json
可能非常糟糕,因为您很可能也在使用json
package,这将导致命名冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.