So I’m working around with a JSON the Telegram API is giving me. I’m trying to get the message value into a string.
Here is my Json.
{
"ok": true,
"result": [
{
"update_id": 855636291,
"message": {
"message_id": 71,
"from": {
"id": 1337,
"first_name": "*",
"last_name": "*",
"username": "*"
},
"chat": {
"id": 1337,
"first_name": "*",
"last_name": "*",
"username": "*"
},
"date": 1435987802,
"text": "Testing"
}
}
]
}
Code I’m trying to use to get the value. (Using Requests btw)
content = json.loads(r)
msg = content['result'][0]['message'][0]['text]
However, it doesn’t work. I managed to retrieve the update_id
with content['result'][0]['update_id']
but I have no idea on how to retrieve the text
.
Thanks in advance!
2
Answers
message
is not a list,text
is a key directly in it:Remove the
[0]
after['message']
Here
message
is a dictionary andtext
is a key which is in that dictionary. Just accesstext
as you would normally in a dictionary.