Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 803 Bytes

193.md

File metadata and controls

33 lines (25 loc) · 803 Bytes
@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"]) 
[上一个例子](192.md) [下一个例子](194.md)