Writing:

vk.method("messages.getConversations", {"offset": 0, "count": 20, "filter": "unanswered"}) 

I get the answer from VK the following answer:

{'count': 1, 'items': [{'conversation': {'peer': {'id': 242369682, 'type': 'user', 'local_id': HereNumber ID}, 'in_read': 185, 'out_read': 186, 'last_message_id': 186, 'unread_count': 1, 'unanswered': True, 'can_write': {'allowed': True}}, 'last_message': {'date': 1556627567, 'from_id ': HereNumber ID,' id ': 186,' out ': 0,' peer_id ': HereNumber ID,' text ':' donate ',' conversation_message_id ': 176,' fwd_messages ': [],' important ': False,' random_id ': 0,' attachments': [], 'is_hidden': False}}], 'unread_count': 1}

How do I get the values ​​from there? Same ID for example. I mean not specifically the ID value through the VKontakte API, but in general the method of obtaining the value from such an array. Those. if it were a simple array, it would be clear that there you could write an array [numberArgument]. Immediately somehow more complicated.

  • one
    import json and the response itself json.loads (answer) - and it will become a dictionary from json'a - Taarim
  • And what print(type(vk.method("messages.getConversations", {"offset": 0, "count": 20, "filter": "unanswered"}))) ? I think you will have dict or str . Most likely, dict . From your answer you can continue to dance :) - gil9red pm
  • This is not an array .. - Enikeyschik
  • @Taarim Isn't json originally a dictionary? - Enikeyschik 2:44 pm

2 answers 2

Try this

 import json response = vk.method("messages.getConversations", {"offset": 0, "count": 20, "filter": "unanswered"}).text response_json = json.loads(response) 

And then you can work with response_json as with dict.

    try using Json.parse() and json.strigify() .

    • 2
      Is it possible in python? - Taarim
    • I did it - Anuar Temirbulat
    • @ AnuarTemirbulat, it turned out on js, on python through the standard json module - no - gil9red