开发者

Convert Unicode Object to Python Dict

开发者 https://www.devze.com 2023-04-08 15:12 出处:网络
A request object that I\'m dealing with has the following value开发者_Go百科 for the key \"address\":

A request object that I'm dealing with has the following value开发者_Go百科 for the key "address":

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

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

Is there any way to deal with this? Do I have to work with the the json.JSONDecoder object?


>>> 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'}
0

精彩评论

暂无评论...
验证码 换一张
取 消