[英]Syntax error when calling "from" attribute of a JSON object
I am using RingCentral API to get call log information.我正在使用 RingCentral API 来获取通话记录信息。
I am interested in an attribute called from
which tells us who was the caller who made the call.我对调用
from
的属性感兴趣,它告诉我们谁是拨打电话的来电者。 To access the caller name, I need to access a call record -> then go to the last leg (root of the call) and then get the from attribute, and then get the name of the caller.要访问来电者姓名,我需要访问通话记录 -> 然后转到最后一段(通话的根)然后获取 from 属性,然后获取来电者的姓名。
Eg:例如:
"from": { "name": "andy murray", "phoneNumber": "+44712345656" }
"from": { "name": "andy murray", "phoneNumber": "+44712345656" }
resp = platform.get('/restapi/v1.0/account/~/call-log', params)
for record in resp.json().records:
print(record.legs[-1].from.name)
After running this command, I am getting error:运行此命令后,我收到错误:
File "demo.py", line 43
print(record.legs[-1].from.name )
SyntaxError: invalid syntax
It looks like Python is not able to comprehend that this "from" is not part of Python itself.看起来 Python 无法理解这个“来自”不是 Python 本身的一部分。 How can I define Python to consider this as an attribute of a JSON object?
如何定义 Python 以将其视为 JSON 对象的属性?
Any help will be appreciated!任何帮助将不胜感激!
Use __dict__
to get all attributes of object.使用
__dict__
获取对象的所有属性。 https://stackoverflow.com/a/39392891/9024042 https://stackoverflow.com/a/39392891/9024042
As mentioned in the answer of the attached post.正如所附帖子的答案中所述。 I called
record.legs[-1].__dict__
and found out all attributes of json object.我调用了
record.legs[-1].__dict__
并找出了 json 对象的所有属性。
I found that, there was no attribute named "from", It was "from_".我发现,没有名为“from”的属性,它是“from_”。
I hope it helps someone with the same issue我希望它可以帮助有同样问题的人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.