Convert Unicode Object to Python Dict

The request object I'm dealing with has the following meaning for the key "address":

u"{u'city': u'new-york', u'name': u'Home', u'display_value': u'2 Main Street'}" 

I need to work with this unicode object as a dictionary. Unfortunately, json.loads () fails because it is not a json-compatible object.

Is there any way to handle this? Should I work with json.JSONDecoder object?

+6
source share
1 answer
 >>> ast.literal_eval(u"{u'city': u'new-york', u'name': u'Home', u'display_value': u'2 Main Street'}") {u'city': u'new-york', u'name': u'Home', u'display_value': u'2 Main Street'} 
+15
source

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


All Articles