python-将字符串转换为字典
json越来越流行,通过python获取到json格式的字符串后,可以通过eval函数转换成dict格式:
>>> a='{"name":"yct","age":10}'
>>> eval(a)
{'age': 10, 'name': 'yct'}
支持字符串和数字,其余格式的好像不支持:
>>> a='{"name":"yct","age":10,"tmp":dddd}'
>>> eval(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'dddd' is not defined