json格式的数据在python中表现为字符串str
类型的数据
import json def json_to_dict(my_json: str) -> dict: return json.loads(my_json) def dict_to_json(my_dict: dict) -> str: return json.dumps(my_dict) if __name__ == '__main__': my_dict = { 'name': "小明", "age": 12, } my_json = dict_to_json(my_dict) print("json格式数据:", my_json) my_dict_from_json = json_to_dict(my_json) print("dict格式数据:", my_dict_from_json)