V
V
Vova Putsyk2015-11-23 23:16:11
Python
Vova Putsyk, 2015-11-23 23:16:11

I have a response from a Post request, it has a String data type. How to translate it into a dictionary?

I have a response from a Post request that looks like:

{"success":true,"result":"ok"}

It is stored entirely in the String type, but you need to translate it into a dictionary.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-11-23
@vovawed

https://docs.python.org/3/library/json.html#json.load

In [3]: from json import loads

In [4]: print(loads('{"success":true,"result":"ok"}'))
{'result': 'ok', 'success': True}

In [5]: print(type(loads('{"success":true,"result":"ok"}')))
<class 'dict'>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question