04-11-2020 09:26 AM
Hi all,
I did a REST API call and I get a response like this:
result = b [{"id":"865776","name":"Cisco","url":"https://abc.com}]"]
I learned, that this is binary object (bold b), but I couldn't find anything to convert.
My question is:
How could I convert this in a Python List/Dictionary, to work on it with the normal
Python List/Dictionary commands?
Many thx in advance
Peter
Solved! Go to Solution.
04-12-2020 01:10 AM
The return normally is string.
If the response is byte-like result ----
response = b'[{"id":"865776","name":"Cisco","url":"https://abc.com}]"}]' -- there are some syntax error in the example ,I added some character (assume that is what you mean)
Convert to string:
response.decode() --- default is utf-8 to string.
Convert to list
response_list = eval(response.decode())
Read the list/dict
response_list[0]['id']
response_list[0]['url]
HTH.
04-11-2020 10:44 AM
Hi,
Could you give more details on the request you did? What application/language do you use for your request? Can you share the response as you see it?
Regards,
Sergiu
04-12-2020 12:54 AM
Hi,
it was REST API (post/get) call against Meraki and I use Python 3.
Peter
04-12-2020 01:10 AM
The return normally is string.
If the response is byte-like result ----
response = b'[{"id":"865776","name":"Cisco","url":"https://abc.com}]"}]' -- there are some syntax error in the example ,I added some character (assume that is what you mean)
Convert to string:
response.decode() --- default is utf-8 to string.
Convert to list
response_list = eval(response.decode())
Read the list/dict
response_list[0]['id']
response_list[0]['url]
HTH.
04-12-2020 02:46 AM
Hi,
my tkx. Yes you right there a typo in my example at the end.
Peter
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide