Convert unicode string dictionary into dictionary in python

前端 未结 5 1836

I have unicode u\"{\'code1\':1,\'code2\':1}\" and I want it in dictionary format.

I want it in {\'code1\':1,\'code2\':1} format.

I

5条回答
  •  盖世英雄少女心
    2020-12-08 02:45

    You can use the builtin eval function to convert the string to a python object

    >>> string_dict = u"{'code1':1, 'code2':1}"
    >>> eval(string_dict)
    {'code1': 1, 'code2': 1}
    

提交回复
热议问题