版本:python3
dumps: dict --> str
import json
my_dict = {"name": "zhangsan", "age": 22}
print(type(my_dict)) # <class 'dict'>
data_str = json.dumps(my_dict)
print(type(data_str)) # <class 'str'>
print(data_str) # {"name": "zhangsan", "age": 22}
loads: str --> dict
import json
my_dict = {"name": "zhangsan", "age": 22}
data_str = json.dumps(my_dict)
print(type(data_str)) # <class 'str'>
data_dict = json.loads(data_str)
print(type(data_dict)) # <class 'dict'>
print(data_dict) # {'name': 'zhangsan', 'age': 22}
好记性不如烂笔头!
|