import json import os kv = {} response_file_path = r"E:/yuxin/cmip6/response" if __name__ == "__main__": for file_name in os.listdir(response_file_path): response_file = open("{}/{}".format(response_file_path, file_name)) response_file_content = response_file.read() response_file.close() response_data_body = json.loads(response_file_content) docs = response_data_body['response']['docs'] for doc in docs: for key in doc: val = doc[key] length = 0 if type(val) == str: length = len(val) elif type(val) == list: length = len(json.dumps(val, ensure_ascii=False)) elif type(val) == int: length = -1 elif type(val) == bool: length = 0 elif type(val) == float: length = -2 if key in kv and length <= kv[key]: continue kv[key] = length print(kv)