json serialization

Load and loads json distinction
  json.load (f) for reading data from the file json, back into the original data format
  json.loads (data) for converting character data into the original data format

  The json.dump ( data, f) for converting the data into a file format json
  json.dumps (data) for converting the data into a data format json

 

dic = {"k": "123"}
with open('dic.json', 'wt', encoding='utf-8') as f:
    json.dump(dic, f)

with open('dic.json', 'rt', encoding='utf-8') as f:
    load_dic = json.load(f)

 

Guess you like

Origin www.cnblogs.com/wujinsheng/p/11316712.html