1. standard module: json

    xiaoxiao2022-07-13  145

    # -*- coding:utf-8 -*- import json dict_sample = dict(Bulls='Michael Jordan', Celtics='Larry Bird', Lakers='Jerry West') dict_sample_chinese = dict(Bulls='米高佐敦', Celtics='大鸟伯德', Lakers='Logo男') # dict instance to json files with open('sample1.json', 'w') as f: json.dump(dict_sample_chinese, f, ensure_ascii=False) # dict instance to str json_str_from_dict = json.dumps(dict_sample) print(json_str_from_dict) # dict from json files with open('sample1.json', 'r') as f: dict_from_json_files = json.load(f) print(dict_from_json_files) # dict from str dict_from_json_str = json.loads(json_str_from_dict) print(dict_from_json_str)

     

    最新回复(0)