How to turn the following data into a Python dict

I am very new to programming and choosing Python as my first language. I can do "POST" via the API, but how do I convert the response I get below to a Python dictionary?

If I were to print the answer, I get:

Response [201]

But if I were to do:

for i in response:
    print i

I get:

{"id":"9e1ebc5d","side":"buy","item":"dinosaur","type":"limit","amount":"1.0000","displayAmount":"1.0000","price":"100","createdTime":"2014-12-24T16:01:15.3404000Z","status":"submitted","metadata":{}}

However, for me this is still useless if I cannot figure out how to convert it into a Python language.

+4
source share
1 answer

Use the function loadsfrom the module json:

import json

# let x be a string contain the JSON encoded data
x = '{"id":"9e1ebc5d", ...}'

# convert to Python dictionary
p = json.loads(x)

# p is now a Python dictionary
print type(p) # prints   <type 'dict'>
print p['id'] # prints   9e1ebc5d
+5
source

Source: https://habr.com/ru/post/1568904/


All Articles