193 json对象转python对象
编辑日期: 2024-11-28 文章阅读: 次
@author jackzhenguo
@desc
@tag
@version
@date 2020/03/31
193 json对象转python对象
python的json
模块loads
方法将json对象转为字典,如下所示:
In [1]: import json
In [2]: json_obj = '{ "Name":"David", "Class":"I", "Age":6 }'
In [3]: python_obj = json.loads(json_obj)
In [4]: type(python_obj)
Out[4]: dict
打印查看相关属性
print("\nJSON data:")
print(python_obj)
print("\nName: ",python_obj["Name"])
print("Class: ",python_obj["Class"])
print("Age: ",python_obj["Age"])