python-small-examples

@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"]) 
[上一个例子](/python-small-examples/md/192.html) [下一个例子](/python-small-examples/md/194.html)