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

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

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2021-09-01
  • 2021-11-16
  • 2021-10-22
  • 2022-12-23
  • 2021-06-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案