Reputation: 33
Soo i have this code
cidade = resp_json['endereco']
the response is
{'logradouro': 'RUA DA BANDEIRA', 'numero': '427', 'complemento': 'Ap 62', 'bairro': 'CABRAL', 'referencia': None, 'cep': '80035270', 'cidade': 'CURITIBA', 'estado': 'PR', 'pais': 'Brasil', 'telefoneFixo': {'ddd': '', 'numero': ''}, 'telefoneAdicional': {'ddd': '41', 'numero': '96739676'}, 'nomeDeQuemIraReceber': 'Adam', 'sobrenomeDeQuemIraReceber': None}
i need grab inside the endereco
the field logradouro
and cidade
how i can do that?
i already try this
cidade = resp_json['endereco'][0]['logradouro']
and dont work.
Upvotes: 1
Views: 19
Reputation: 6449
python parses json as a dictionary, and you can't access a dictionary value by index.
So to get the field "logradouro" you should just do this:
cidade = resp_json['endereco']['logradouro']
Upvotes: 1