菜鸟IT的博客 >> Python
Python 如何将字符串转为字典 | literal_eval
Python 如何将字符串转为字典
https://www.cnblogs.com/OnlyDreams/p/7850920.html
>>> import ast
>>> user = '{"name" : "john", "gender" : "male", "age": 28}'
>>> user_dict = ast.literal_eval(user)
>>> user_dict
{'gender': 'male', 'age': 28, 'name': 'john'}
user_info = "{'name' : 'john', 'gender' : 'male', 'age': 28}"
>>> user_dict = ast.literal_eval(user)
>>> user_dict
{'gender': 'male', 'age': 28, 'name': 'john'}
菜鸟IT博客[2022.04.05-00:11] 访问:464