Answer the question
In order to leave comments, you need to log in
How to extract certain objects from a string in python?
I work with vk_api, with such a request
usr = vk.users.get(user_id=event.user_id)
I get this:
[{'id': мой ади, 'first_name': 'имя', 'last_name': 'фамилия', 'is_closed': False, 'can_access_closed': True}]
Answer the question
In order to leave comments, you need to log in
Another bot-writing who does not want to learn the basics of the language, they are tired.
PS: go learn the basics, work with data structures - lists and dictionaries.
Kot Kotov don't listen to them.
There is such a JSON format, this is just your string.
To do so: usr[0]["last_name"] will be only the most uneducated person.
So let's deal with your JSON:
user = vk.users.get(user_id=event.user_id)
user_json = json.loads(user)
print(user_json['last_name'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question