json.dumps()的作用是将字典类型转换为字符串类型。
>>> import json
>>> data = {"name":"xiaoming","age":"18","hobby":"swimming"}
>>> print(data,type(data))
{'name': 'xiaoming', 'age': '18', 'hobby': 'swimming'} <class 'dict'>
>>> datas=json.dumps(data)
>>> print(datas,type(datas))
{"name": "xiaoming", "age": "18", "hobby": "swimming"} <class 'str'>
json.loads()的作用是将字符串类型转换为字典类型。
>>> print(datad,type(datad))
{'name': 'xiaoming', 'age': '18', 'hobby': 'swimming'} <class 'dict'>