There is such code:

param = {'user_id': 1, "field": 'bdate', 'v': 5.52} url = 'https://api.vk.com/method/users.get?' + parse.urlencode(param) resp = request.urlopen(url).read().decode("utf8") json_data = json.dumps(resp) parsed_json = json.loads(json_data) 

How to get data from json answer? I tried this:

 print(parsed_json[0]['id']) 

So:

 print(parsed_json["response"]['id']) 

But nothing works. Python version 3.5.

  • "nothing works" - a loose concept. Struktreys in the studio. - Constantine
  • It seems that this is generally superfluous: json_data = json.dumps (resp) - Chp

2 answers 2

Judging by the vk docks, the answer should be {"response":[{"id":210700286, ... , means to get id:

 id = parsed_json["response"][0]["id"] 

    Use vk-requests , the library implements everything you need and is very convenient to use.

    Example of use:

     import vk_requests api = vk_requests.create_api(app_id=123, login='User', password='Password') api.users.get(user_ids=1) [{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}] 

    That is, you do not need to worry about how to get the data; this happens automatically in a format that the developer can understand.