Convert a String representation of a Dictionary to a dictionary?

前端 未结 9 1004
醉酒成梦
醉酒成梦 2020-11-21 05:22

How can I convert the str representation of a dict, such as the following string, into a dict?

s = \"{\'muffin\' : \'l         


        
9条回答
  •  眼角桃花
    2020-11-21 05:44

    using json.loads:

    >>> import json
    >>> h = '{"foo":"bar", "foo2":"bar2"}'
    >>> d = json.loads(h)
    >>> d
    {u'foo': u'bar', u'foo2': u'bar2'}
    >>> type(d)
    
    

提交回复
热议问题